Plot function into subplots
Mostrar comentarios más antiguos
Hey,
I have a function which creates a plot. Now I want to run this function multiple times and put each plot into a subplot slot.
It should be something like this:
function[] = myplot(x,y)
plot(x,y);
end
subplot(3,1,1) = myplot(input_x1,input_y1);
subplot(3,1,2) = myplot(input_x2,input_y2);
subplot(3,1,3) = myplot(input_x3,input_y3);
This doesn't seem to work, is there an easy way to do this? Maybe with an appropriate output for the function which can be used?
Or maybe with the correct plot handle?
Any help for a simple solution would be nice.
Thanks.
Respuesta aceptada
Más respuestas (2)
KALYAN ACHARJYA
el 12 de Ag. de 2019
Editada: KALYAN ACHARJYA
el 12 de Ag. de 2019
Is there an easy way to do this?
function myplot(x,y)
plot(x,y);
end
Main Script: Examples. Considering all x & y have different functions and ranges
% Define all x y data
% Thease are just examples
input_x1=[1:10];
input_y1=exp(input_x1);
input_x2=[11:20];
input_y2=log(input_x2)
input_x3=[31:45];
input_y3=exp(-input_x3);
%% Plots
subplot(3,1,1),myplot(input_x1,input_y1);
subplot(3,1,2),myplot(input_x2,input_y2);
subplot(3,1,3),myplot(input_x3,input_y3);
Result:

1 comentario
Daniel Schmidt
el 12 de Ag. de 2019
Kabil
el 15 de Dic. de 2025
0 votos
>> x = linspace(0,1,1000);
>> y = sin(2*pi*5*x);
>> z = cos(2*pi*5*x);
>> a = y+z;
>> subplot(3,1,1),plot(x,y);
>> subplot(3,1,2),plot(x,z);
>> subplot(3,1,3),plot(x,a);
>>
Categorías
Más información sobre Subplots en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!