contour plot problem Z must be at least a 2x2 matrix

Hallo everyone,
i have a problem to make the contour plot, it always shows Z must be at least a 2x2 matrix. i have try my best to solve, but it still not work, could you please to help me? The code is as follows.
x=[80;100;90;90;90]
x = 5x1
80 100 90 90 90
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
y=[4;4;2;6;4]
y = 5x1
4 4 2 6 4
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
[X,Y] = meshgrid(x,y)
X = 5x5
80 100 90 90 90 80 100 90 90 90 80 100 90 90 90 80 100 90 90 90 80 100 90 90 90
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Y = 5x5
4 4 4 4 4 4 4 4 4 4 2 2 2 2 2 6 6 6 6 6 4 4 4 4 4
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
% Polly 11 f(x,y)=p00+p10*x+p01*y
f1=1.7419-0.0006*x+0.0132*y
f1 = 5x1
1.7467 1.7347 1.7143 1.7671 1.7407
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
contour(X,Y,f1)
Error using contour (line 48)
Z must be at least a 2x2 matrix.
Thanks and best regards
JL

 Accepted Answer

Anotther option, using the scatteredInterpolant function —
x=[80;100;90;90;90]
x = 5x1
80 100 90 90 90
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
y=[4;4;2;6;4]
y = 5x1
4 4 2 6 4
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
[X,Y] = meshgrid(x,y);
X = 5x5
80 100 90 90 90 80 100 90 90 90 80 100 90 90 90 80 100 90 90 90 80 100 90 90 90
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Y = 5x5
4 4 4 4 4 4 4 4 4 4 2 2 2 2 2 6 6 6 6 6 4 4 4 4 4
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
% Polly 11 f(x,y)=p00+p10*x+p01*y
f1=1.7419-0.0006*x+0.0132*y
f1 = 5x1
1.7467 1.7347 1.7143 1.7671 1.7407
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Fz = scatteredInterpolant(x, y, f1)
Fz =
scatteredInterpolant with properties: Points: [5x2 double] Values: [5x1 double] Method: 'linear' ExtrapolationMethod: 'linear'
F1 = Fz(X,Y)
F1 = 5x5
1.7467 1.7347 1.7407 1.7407 1.7407 1.7467 1.7347 1.7407 1.7407 1.7407 1.7203 1.7083 1.7143 1.7143 1.7143 1.7731 1.7611 1.7671 1.7671 1.7671 1.7467 1.7347 1.7407 1.7407 1.7407
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
contour(X,Y,F1)
.

4 Comments

Hallo Star,
Thanks so much for your reply, according to your experience, if i want to do this follwing contour plot use only these point, whether it is possible? x and y as the x axis and y axis, and f1 as Z axis,
Thanks so much for you effort.
My pleasure!
I am not certain what you want. The image is of a surfc plot, with additional contour offsets using ZLocation. (I was not aware that more than one was possible, however it could be using the hold function as well. I have never tried that.)
As for setting specific contours, you can do that by selecting LevelList, however with a surfc plot, you would need to do that in a handle to the plot.
That would go something like this —
[X,Y,Z] = peaks;
figure
hsc1 = surfc(X, Y, Z)
hsc1 =
2x1 graphics array: Surface Contour
colormap(turbo)
hsc1(2).LevelList = [min(Z(:)):0.5:-1 1:0.5:max(Z(:))];
hsc1(2).ZLocation = -10;
hold on
hsc2 = surfc(X, Y, Z)
hsc2 =
2x1 graphics array: Surface Contour
colormap(turbo)
hsc2(2).LevelList = [min(Z(:)):0.5:-1 1:0.5:max(Z(:))];
hsc2(2).ZLocation = 10;
hold off
view(-27,45)
This seems to be close to the plopt image you posted. The ZLocation property only accepts an integer argument, so using hold to draw the surface plot twice appears to be the only option oi more than one contour is desired.
.
Hallo Star,
That is so kind of you. It helps me really a lot. :)
Actually what I want is to see How f1 changes with x and y, or how it distributed with different x and y by contour plot, i thought the contour plot will be like the pictures i sent it you, however it is not.
Thanks so much again for your help. That is really important to me. If i have questions i may contact to you again.
Best regards
JL
As always, my pleasure!
I will gladly help you with any further questions.

Sign in to comment.

More Answers (1)

x=[80;100;90;90;90];
y=[4;4;2;6;4];
[X,Y] = meshgrid(x,y);
% Polly 11 f(x,y)=p00+p10*x+p01*y
f1=1.7419-0.0006*X+0.0132*Y;
contour(X,Y,f1)

4 Comments

Hallo Walter
Thanks so much for your reply, I check the code you use which is not difference from me, why when I run this, it always show 2d Matrix prolem? and what i actually want is like x and y as the x axis and y axis, and f1 as Z axis, like this. whether it is possible to do it?
Thanks so much.
Your original code used
f1=1.7419-0.0006*x+0.0132*y
which refers to the vector x and y
The revised code uses
f1=1.7419-0.0006*X+0.0132*Y;
which refers to the grids X and Y
Your plot is similar to what you would get if you used surfc
Hallo Walter,
Thank you so much.
I should be have been more careful. i will use the surfc to check.
Thanks again.
JL

Sign in to comment.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Tags

Asked:

JM
on 25 Jul 2024

Commented:

on 25 Jul 2024

Community Treasure Hunt

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

Start Hunting!