Adding multiple function plots to a single figure with subplots - MATLAB
15 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I've been trying to run a function three times that plots 2 sub-plots (6 plots total) onto on singular figure.
So I've got a function that reads in a dataset and a manipulator, then manipulates it in 2 different ways, then plots in 2 subplots - the function works as it should, I just can't seem to merge the plots when I'm running it in a seperate script.
Simplified function below:
function function_plot(dataset,manipulator)
%Manipulates Data
figure;
subplot(1,2,2);
imagesc(data_manipulated1);
subplot(1,2,1);
imagesc(data_manipulated2);
end
Simplified script below:
function_plot('data.mat',manipulator1);
function_plot('data.mat',manipulator2);
function_plot('data.mat',manipulator3);
I've also tried the below - but this gives the error "Too many output arguments"
function function_plot(dataset,manipulator,myfigure)
%Manipulates Data
if nargin<4
myfigure = figure;
else
figure(myfigure);
end
subplot(1,2,2);
imagesc(data_manipulated1);
subplot(1,2,1);
imagesc(data_manipulated2);
end
Simplified script:
myfigure = function_plot('data.mat',manipulator1);
function_plot('data.mat',manipulator2,myfigure);
function_plot('data.mat',manipulator3,myfigure);
1 comentario
Paul
el 29 de Dic. de 2025
To be clear, you want three outputs of imagesc overlaid on one subplot and three outputs of imagesc overlaid on the other subplot?
Respuestas (2)
Matt J
el 29 de Dic. de 2025
Editada: Matt J
el 29 de Dic. de 2025
This might be what you want:
Manipulators={manipulator1,manipulator2,manipulator3};
m=3;n=2; %tiling dimensions
%create handles
figure;
ax=gobjects(n,m);
for i=1:m*n;
ax(i)=subplot(m,n,i);
end
ax=ax';
%populate the axes
for j=1:3
function_plot(ax(j,:),dataset,Manipulators{j});
end
function function_plot(ax,dataset,manipulator)
imagesc(ax(1), data_manipulated2);
imagesc(ax(2), data_manipulated1);
end
0 comentarios
Ver también
Categorías
Más información sobre Annotations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!