Using the 'Surf' command for variable 'x' values

I am trying to use the Surf command. Here's the data that I have:
x= [1.158633 4.871195 7.667851 11.45038 22.11895
1.221922 3.777088 7.641091 11.52413 21.89302
1.52861 4.609719 7.60228 12.06438 21.33681
1.934019 6.881875 9.591649 13.51807 21.30859 ];
y=[0 12.5 25 37.5];
[xx, yy]=meshgrid(x, y)
zz=[ 0.000522 0.000549 0.000557 0.000623 0.000222
0.000584 0.000476 0.000566 0.00062 0.000194
0.000557 0.000528 0.00065 0.000594 0.000144
0.000603 0.000514 0.000588 0.000606 0.000206 ];
The problem is, the 'y' value is the same for every 4 points in the zz matrix but the x value differs. Because of that, surf doesn't work. If all x values were something like [1.5 5 8 12 21], it would work perfectly. But they differ a little. Any suggestions what I can do?

 채택된 답변

Star Strider
Star Strider 2019년 3월 23일

0 개 추천

It doesn’t work because ‘y’ is a vector.
Try this:
x= [1.158633 4.871195 7.667851 11.45038 22.11895
1.221922 3.777088 7.641091 11.52413 21.89302
1.52861 4.609719 7.60228 12.06438 21.33681
1.934019 6.881875 9.591649 13.51807 21.30859 ];
y=[0 12.5 25 37.5];
yy = repmat(y, size(x,2), 1)';
zz=[ 0.000522 0.000549 0.000557 0.000623 0.000222
0.000584 0.000476 0.000566 0.00062 0.000194
0.000557 0.000528 0.00065 0.000594 0.000144
0.000603 0.000514 0.000588 0.000606 0.000206 ];
figure
surf(x, yy, zz)
grid on

댓글 수: 2

It worked! Thank you so much! :)
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

태그

질문:

2019년 3월 22일

댓글:

2019년 3월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by