Reseting and refresing figure with tiledlayout/nexttitle

31 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

Matt J
Matt J il 17 Nov 2022
Modificato: Matt J il 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 Commenti

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Data Exploration in Help Center e File Exchange

Prodotti


Release

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by