put me out of my misery

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 Comments

Iain
Iain on 31 Jan 2014
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)
Rizwana
Rizwana on 31 Jan 2014
Edited: Rizwana on 31 Jan 2014
my x is a 1 col,264 row matrix reading radius,y is 1 col,264 row matrix reading angles in degrees. and z is pressure gain 1* 264. I want to plot radius versus circumferential angle in degrees with contours of pressure. Thank you

Sign in to comment.

 Accepted Answer

Bjorn Gustavsson
Bjorn Gustavsson on 31 Jan 2014
Edited: Bjorn Gustavsson on 31 Jan 2014
First you have to get yourself a good overview of what you actually have, I suggest using scatter:
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 Comments

Rizwana
Rizwana on 3 Feb 2014
Edited: Rizwana on 3 Feb 2014
Than you for your help. Iam great full to you for teaching me so many things in simple 5 lines of codes:). Just one doubt... You have done radius* cos(theta) for qwe(:,1).*cos(qwe(:,2)*pi/180) and radius * sin(theta) for qwe(:,1).*sin(qwe(:,2)*pi/180)... While plotting do we should convert degrees into radian??? because you have multiplied it with pi/180?? Is it compulsory???
Yes, the trigonometric functions work on radians. You'd be better off learning to use radians.

Sign in to comment.

More Answers (3)

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 Comments

My Z matrix is already defined as 1* 264 matrix. These are just set of 1 col readings 264 reading. I cant use Z = sin(X)+cos(X+Y) because Z is no where in my experiment related by that formula. Thank you.
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.
I will attach an excel file. 1st row is radius, 2nd row is circumferential angle in degrees and z is 3rd row whose contours i need to plot... This is just experimental data collected... are you trying to get idea of what iam trying to plot???

Sign in to comment.

Iain
Iain on 31 Jan 2014
Edited: Iain on 31 Jan 2014
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 Comments

Rizwana
Rizwana on 31 Jan 2014
Edited: Rizwana on 31 Jan 2014
Nope i dont want to subplot.. I need contour of circumferential pressure(z=1*264 matrix) with radius on y-axis(1*264) and circumferential angle in degrees(1*264) on x-axis.. If i give you my data can you help me out..?
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.
Its total pressure coefficient(z). In a turbine blade, pressure varies with radius and pitch variation... z is just set of data. Not a function.

Sign in to comment.

Walter Roberson
Walter Roberson on 31 Jan 2014

0 votes

7 Comments

its giving me error saying
Undefined function or method 'scatteredInterpolant' for input arguments of type 'double'.
I did say it was new. Use TriScatteredInterp then.
x = rand(100,1)*4-2; y = rand(100,1)*4-2; z = x.*exp(-x.^2-y.^2); >> F = TriScatteredInterp(x,y,z);
??? Undefined function or method 'TriScatteredInterp' for input arguments of type 'double'.
Could you remind me of which MATLAB version you are using?
matlab 7.6.0(R2008a)
It appears that TriScatteredInterp appeared in R2009a. griddata() does exist in your release though.
Thank you. I will try downloading new 2013 version. Thank you very much for highlighting the other 2 functions i can use.

Sign in to comment.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!