put me out of my misery
1 次查看(过去 30 天)
显示 更早的评论
i have 3 matrices..
x = 1 * 264;
y = 1* 264;
z = 1 * 264;
contour(x,y,z) % error z must be 2* 2 or more
hence i did
[X,Y] = meshgrid(x,y); Z =griddata(x,y,z,X,Y);
contour(X,Y,Z) is giving some weird plot. Not desirable.
Now how to do it...
2 个评论
Iain
2014-1-31
What are you trying to plot?
contour(x,y,z) is expecting x to be a vector with n elements, y a vector with m elements, and z to be n by m (or is it m by n)
采纳的回答
Bjorn Gustavsson
2014-1-31
编辑:Bjorn Gustavsson
2014-1-31
qwe = xlsread('yourfile.xls');
scatter(qwe(:,1).*cos(qwe(:,2)*pi/180),...
qwe(:,1).*sin(qwe(:,2)*pi/180),15,...
(qwe(:,3)-min(qwe(:,3)))*5+5,'filled')
So there you see some odd spots (sensor faulty or something?). At least easy to reinterpolate outside that region:
X = 24.7:0.1:27;
Y = 0:0.1:5;
[X,Y] = meshgrid(X,Y);
Z = griddata(qwe(:,1).*cos(qwe(:,2)*pi/180),...
qwe(:,1).*sin(qwe(:,2)*pi/180),qwe(:,3),X,Y);
% Or any of the newer variants like Walter suggested.
% do the contour:
hold on
contour(X,Y,Z,1.25:0.025:max(qwe(:,3)),'b')
HTH
2 个评论
Bjorn Gustavsson
2014-2-3
Yes, the trigonometric functions work on radians. You'd be better off learning to use radians.
更多回答(3 个)
Mischa Kim
2014-1-31
Rizwana, first option works just fine. Make sure that Z is an mxn matrix, where m and n are the length of the two vectors x and y. meshgrid , e.g., generates an appropriate grid.
x = rand(10,1);
y = rand(10,1);
[X,Y] = meshgrid(x,y);
Z = sin(X)+cos(X+Y);
figure
contour(X,Y,Z)
or see the documentation.
3 个评论
Mischa Kim
2014-1-31
The contour plot is more of a 3D type plot, where the dependent variable (Z) depends on two variables (X, Y). So it is not quite clear to me what you would like to achieve.
Iain
2014-1-31
编辑:Iain
2014-1-31
Looks like you actually want: plotyy or subplots:
plotyy(x,y,x,z) % plot angle against radius on the left hand y axis, and pressure against radius on the right hand y axis.
subplot(211)
plot(x,y)
subplot(212)
plot(x,z)
or
subplot(121)
plot(x,y)
subplot(122)
plot(x,z)
obviously, switch the x,y,z's around to plot against what you want to. - contour plots are only valid for 2-D signals, and you've only got 3 1D signals.
3 个评论
Iain
2014-1-31
Is circumferential pressure supposed to be a function of angle and radius?
If radius has "n" elements, and you have "m" angles, then you should get "n x m" pressures, and not have all three as being vectors.
For example, with a trivial function I know is wrong:
x= 0:0.1:1;
y= 0:36:360;
z = x' * y;
contour(x,y,z)
would work.
Walter Roberson
2014-1-31
7 个评论
Walter Roberson
2014-1-31
It appears that TriScatteredInterp appeared in R2009a. griddata() does exist in your release though.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!