Filter löschen
Filter löschen

Reseting and refresing figure with tiledlayout/nexttitle

17 Ansichten (letzte 30 Tage)
Jack Daniels
Jack Daniels am 17 Nov. 2022
Kommentiert: Jack Daniels am 17 Nov. 2022
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?

Akzeptierte Antwort

Matt J
Matt J am 17 Nov. 2022
Bearbeitet: Matt J am 17 Nov. 2022
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 Kommentare
Jack Daniels
Jack Daniels am 17 Nov. 2022
Now, it wokrs, perfect!
Thank you!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by