Plot function into subplots
Ältere Kommentare anzeigen
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.
Akzeptierte Antwort
Weitere Antworten (2)
KALYAN ACHARJYA
am 12 Aug. 2019
Bearbeitet: KALYAN ACHARJYA
am 12 Aug. 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 Kommentar
Daniel Schmidt
am 12 Aug. 2019
Kabil
am 15 Dez. 2025
0 Stimmen
>> 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);
>>
Kategorien
Mehr zu Subplots finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!