Reseting and refresing figure with tiledlayout/nexttitle

31 次查看(过去 30 天)
I am trying to plot and refresh the figure which I created with "tiledlayout"
function out = mtrx_surf(Z3)
persistent srf
if isempty(srf)
x = 1:30;
[X30, Y30] = meshgrid(x);
%Z30 = ones(30);
Z30 = imresize(Z3,[30 30],"bilinear")';
tiledlayout(1,2)
nexttile
srf = surf(X30,Y30,Z30);
axis([0 30 0 30 -5 80])
clim([20 60])
nexttile
srf = surf(X30,Y30,Z30);
shading interp
axis([0 30 0 30 -5 80])
clim([20 60])
else
Z30 = imresize(Z3,[30 30],"bilinear")';
% tiledlayout(1,2)
nexttile
srf.ZData = Z30;
axis([0 30 0 30 -5 80])
clim([20 60])
nexttile
srf.ZData = Z30;
shading interp
% axis([0 30 0 30 -5 80])
% clim([20 60])
%puase(0.5)
end
out = 1;
clear surf
end
It turns out that at very first step I am able to create plot with 2 tiles
on the next time as "else" is evaluted then it crashes ... and no plots.
How can I evalute, reset, refresh the same plot when using tiledlayout function to be able to plot multi-charts on the same figure? How can I optimized tehe my function?

采纳的回答

Matt J
Matt J 2022-11-17
编辑:Matt J 2022-11-17
One possibility:
A(2,2)=60;
mtrx_surf(A)
ans = 1
A(2,2)=30;
mtrx_surf(A)
ans = 1
function out = mtrx_surf(Z3)
persistent srf
if isempty(srf)
clear srf
x = 1:30;
[X30, Y30] = meshgrid(x);
%Z30 = ones(30);
Z30 = imresize(Z3,[30 30],"bilinear")';
tiledlayout(1,2)
nexttile
srf(1) = surf(X30,Y30,Z30);
axis([0 30 0 30 -5 80])
clim([20 60])
nexttile
srf(2) = surf(X30,Y30,Z30);
shading interp
axis([0 30 0 30 -5 80])
clim([20 60])
else
Z30 = imresize(Z3,[30 30],"bilinear")';
srf(1).ZData = Z30;
axis([0 30 0 30 -5 80])
clim([20 60])
nexttile
srf(2).ZData = Z30;
shading interp
end
out = 1;
end
  3 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Exploration 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by