Re: [問題] 使用Matlab讀txt檔畫3D圖

看板MATLAB作者 (prof)時間11年前 (2014/01/22 03:05), 編輯推噓2(200)
留言2則, 1人參與, 最新討論串2/2 (看更多)
※ 引述《vacuousrock (只是過客)》之銘言: : 小弟因為研究的需求,需將量測的天線場型data用Matlab畫出 : data為三個一維矩陣,如下所示 : Theta Phi Directivity : 0 0 -1.275 : 5 0 0.3321 : 10 0 1.572 : 180 0 -0.9896 : 0 5 -1.275 : 5 5 2.509 : 180 5 -0.9896 : : : 180 355 -0.9896 : 完整data連結:http://ppt.cc/305a : 照道理說畫出來的圖形應該會長這樣:http://ppt.cc/YHSp : 只不過,小弟參照一些網路上的程式碼,畫了許久 : 圖形卻始終長得不太一樣:http://ppt.cc/rdAc : 不曉得是哪些步驟或邏輯有錯 : 底下附上小弟的程式碼,麻煩版上的大大幫忙指點迷津 : 謝謝 : ---- : clear all : close all : clc : A = load('farfield.txt'); : theta = A(:,1); : phi = A(:,2); : r = A(:,3); : theta = theta*pi/180; : phi = phi*pi/180; : theta = meshgrid(theta); %這三行meshgrid,總覺得哪裡怪怪的,不太明白和 : phi = meshgrid(phi); %[theta, phi] = meshgrid(theta, phi)的差別 : r = meshgrid(r); %而r = meshgrid(r)把同一column上每點值大小變一樣 : %似乎不太對 : [x, y, z] = sph2cart(phi, theta, r); : mesh(x,y,z) 簡單寫了一下 大概長這樣: clear; clc; close all; format long; A = load('farfield.txt'); theta=zeros(37,72); theta(:)=A(:,1)*pi/180; %把讀進來的theta變成37*72的矩陣 phi=zeros(37,72); phi(:)=A(:,2)*pi/180; %同上 r=zeros(37,72); r(:)=10.^(A(:,3)/20); %同上,此外direvtivity單位轉回去 [x,y,z]=sph2cart(phi,(pi/2-theta),r); %matlab的theta跟常用的不同 figure(); surf(x,y,z,20*log10(sqrt(x.^2+y.^2+z.^2)),'edgecolor','none'); hold on; colorbar; %20*log10(sqrt(x.^2+y.^2+z.^2))這個是他標顏色的基準 把他轉回dBi就好 我不太確定你要畫的場形圖是用場還是場的平方(power), 我這邊是用場 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.247.141

01/22 20:44, , 1F
感謝p大詳細的回答 我大概明白了
01/22 20:44, 1F

01/22 20:46, , 2F
用你提供的方法 矩陣小了很多 感謝
01/22 20:46, 2F
文章代碼(AID): #1ItiJTJV (MATLAB)
討論串 (同標題文章)
文章代碼(AID): #1ItiJTJV (MATLAB)