我用定向光束做了一个实验,我想把它想象一下。设置是这样的:
我在22度,15度,10度,5度和0度测量了我在100,75,50和25厘米距离的值。
现在我想将此数据导入3D waterfall()
图表,其中源是最高峰值,您可以看到电压在所有方向上都会降低。
所以我的第一个想法是单独适应所有距离,我希望将这些功能放入 waterfall()
。但是这并不能很好地工作,因为在我将它们计算到x
,y
系统之后,开始和结束不同的值层(看一下示例代码)是不同的。
那么,我如何将我的数据导入瀑布图?
clearvars
x=-1:0.1:1;
%________________________________________________________measured Values (layers)
A=[208; 256; 480; 704; 776; 752; 672; 480; 264]; % 0.25m
B=[104; 156; 304; 388; 432; 440; 340; 280; 140]; % 0.50m
C=[ 54; 104; 250; 264; 320; 270; 252; 144; 70]; % 0.75m
D=[ 32; 64; 142; 198; 228; 208; 130; 86; 46;]; % 1.00m
% plot(A)
% figure(2)
% plot(B)
% figure(3)
% plot(C)
% figure(4)
% plot(D)
%________________________________________________________to x,y System
dist1=[tand(-22)*0.25; tand(-15)*0.25; tand(-10)*0.25; tand(-5)*0.25; tand(0)*0.25; tand(5)*0.25; tand(10)*0.25; tand(15)*0.25; tand(22)*0.25;];
dist2=[tand(-22)*0.50; tand(-15)*0.50; tand(-10)*0.50; tand(-5)*0.50; tand(0)*0.50; tand(5)*0.50; tand(10)*0.50; tand(15)*0.50; tand(22)*0.50;];
dist3=[tand(-22)*0.75; tand(-15)*0.75; tand(-10)*0.75; tand(-5)*0.75; tand(0)*0.75; tand(5)*0.75; tand(10)*0.75; tand(15)*0.75; tand(22)*0.75;];
dist4=[tand(-22); tand(-15); tand(-10); tand(-5); tand(0); tand(5); tand(10); tand(15); tand(22)];
plot(dist1,A)
figure(2)
plot(dist2,B)
figure(3)
plot(dist3,C)
figure(4)
plot(dist4,D)
% func1= fit(dist1,A,'poly2')
%
% plot(dist1, func1(dist1))
此外:
结果我想创建这样的东西:
http://de.mathworks.com/help/matlab/ref/waterfall.html
或者可能是表面:
http://de.mathworks.com/help/matlab/ref/surf.html
但我不知道如何将当前数据转换为适合 waterfall()
或 surf()
<的要求的格式/ strong>功能
答案 0 :(得分:4)
关于组织数据的全部内容。正如丹尼尔所说,waterfall
(或者甚至是surf
)需要网格作为输入(您的数据需要是矩阵)。
因此,让我们为您的数据构建一个合适的网格:
%% // measured Values (layers)
A = [208; 256; 480; 704; 776; 752; 672; 480; 264] ; %// 0.25m
B = [104; 156; 304; 388; 432; 440; 340; 280; 140] ; %// 0.50m
C = [ 54; 104; 250; 264; 320; 270; 252; 144; 70] ; %// 0.75m
D = [ 32; 64; 142; 198; 228; 208; 130; 86; 46] ; %// 1.00m
%% // Building the mesh
%// primary parameters
x = (0.25:0.25:1).' ; %'// ignore that comment
angles = [-22 -15 -10 -5 0 5 10 15 22] ;
%// mesh matrices
X = x * ones(1,numel(angles)) ; %// distance to source
Y = x * tand(angles) ; %// lateral spread due to angle
V = [A B C D].' ; %'// measurements (voltages)
此时,您有3个矩阵X
,Y
和V
,它们是大多数3D图形功能的完美输入,例如surf
或waterfall
。所以它变得非常简单:
%% // Waterfall visualisation
hf = figure ;
hw = waterfall(X,Y,V) ;
如果您想添加一些改进:
%% // refinements
shading interp
xlabel('Distance to source')
ylabel('Lateral spread')
zlabel('Voltage')
hold on
plot3(0,0,0,'or','MarkerSize',10,'LineWidth',4) %// show the source position
和/或有关该图的更多信息:
%% // displays the base rays
xrays = [0;x] ;
yrays = [zeros(1,numel(angles)) ; Y] ;
set(0,'DefaultAxesColorOrder',[0 0 0] , 'DefaultAxesLineStyleOrder','--|:' )
plot(xrays,yrays,'Marker','.')
在此阶段,它会生成下图,但您可以保持简单或调整所有图形对象的许多其他属性以个性化您的显示:
您也可以使用surf
功能代替waterfall
,并使用相同的矩阵作为输入。
更好地链接为每个传感器位置记录的电压的另一种方法是使用stem
图。不幸的是stem
函数不会将3D数组作为输入,但ZData
属性仍然存在,因此我们可以先实例化干图,然后遍历它们以设置它们的ZData
:
%% // STEM waterfall variant
hsf = figure ; hold on
hs = stem(X.',Y.',':ob') ;
for k=1:4
set(hs(k),'ZData',V(k,:))
end
通过上述所有改进,它产生:
此变体不会对电压进行颜色编码,但会准确显示记录的位置。
答案 1 :(得分:1)
最简单的方法是首先对数据进行网格划分(即将它们放在X,Y和Z矩阵中):
%Z:
dist1234=[dist1 dist2 dist3 dist4];
%Y:
ABCD=[A B C D];
%X:
[n1,n2]=size(ABCD);
X=repmat(1:n2,n1,1); % or whatever your x-axis is, here it is 1, 2, 3...
% Take your pick:
figure(1)
surf(X,dist1234,ABCD);title('surf')
figure(2)
waterfall(X',dist1234',ABCD');title('waterfall')
figure(3)
mesh(X,dist1234,ABCD);title('mesh')