作者profyang (prof)
看板MATLAB
标题Re: [问题] 使用Matlab读txt档画3D图
时间Wed Jan 22 03:04:51 2014
※ 引述《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
1F:推 vacuousrock:感谢p大详细的回答 我大概明白了 01/22 20:44
2F:推 vacuousrock:用你提供的方法 矩阵小了很多 感谢 01/22 20:46