Create surf (3D plot) with axis limitation from 2D matrix - animated

I am trying to create "mesh" (surf) out of 2D matrix which is changing by time on its values
x = 1:30;
y = x;
Z = [ 1 1 1; 1 1 1; 1 1 1];
[X30 , Y30] = meshgrid(x,y);
a=1;
for inc = 1:30
Z30 = imresize (Z,[30 30],'bicubic');
a = a + 1;
Z(2,2) = a;
surf(X30,Y30,Z30)
axis([0 30 0 30 0 30])
pause(0.5)
end
The "surf" shows plot with "auto" axis limitation and after applying "axis" function are the size limited, so I have two plots refreshed subsequently - can be set the axis of surf once?

 채택된 답변

Cris LaPierre
Cris LaPierre 2022년 11월 13일
편집: Cris LaPierre 2022년 11월 13일
Each time you call the surf function, you get a brand new axes. This means any settings set in the previous axes are lost, and must be reset.
It looks like you just want to update the Z values of your surface. You can do that by accessing the ZData property of your plot. Try this.
x = 1:30;
[X30 , Y30] = meshgrid(x);
Z = [ 1 1 1; 1 1 1; 1 1 1];
Z30 = imresize (Z,[30 30],'bicubic');
sf = surf(X30,Y30,Z30);
axis([0 30 0 30 0 30])
for a = 1:30
Z(2,2) = a;
Z30 = imresize (Z,[30 30],'bicubic');
sf.ZData = Z30;
pause(0.5)
end

댓글 수: 5

Jack Daniels
Jack Daniels 2022년 11월 14일
편집: Jack Daniels 2022년 11월 14일
Thanks!
Just couriousity: As very first step the 3D surf looks like ("greenish")
on second step - it truns the most of the "pixeles" ( Z(x,y) < 1 ) into blue...
I understand there is already "interpolated" Z30 matrix (no pure 1's there and values are >1) but is it the color change normal (due to colormap) from "greenish" to "blueish"?
Thank you very much for your help!
The color is based on the range of data in Z, and scales to cover the entire range. When the values are all 1, there is no variation, so the color everywhere is set to the middle of the color scale, which is the green you see. As soon as some variation is introduced, the high is set to yellow, and the low to blue. With your data, that results in most of the data being set to blue.
I believe what you want to do is also set the color scale limits at the same time you set the X,Y, and Z axis limits. You can do that using clim. Here is the same code with that added (I removed the for loop so you can see the result).
x = 1:30;
[X30 , Y30] = meshgrid(x);
Z = [ 1 1 1; 1 1 1; 1 1 1];
Z30 = imresize (Z,[30 30],'bicubic');
sf = surf(X30,Y30,Z30);
axis([0 30 0 30 0 30])
clim([0 30])
Wow. Perfect!
Look into the options available in the axis command, in particular the 'style' options.
I don't understand the rest of yoru questions, but they appear to be more about app designer, so I would suggest starting a new question for that.
That's correct. It's about the AppDesigner.

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

추가 답변 (0개)

카테고리

제품

릴리스

R2022b

질문:

2022년 11월 11일

댓글:

2022년 11월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by