Plot function into subplots
Show older comments
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.
Accepted Answer
More Answers (2)
KALYAN ACHARJYA
on 12 Aug 2019
Edited: KALYAN ACHARJYA
on 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 Comment
Daniel Schmidt
on 12 Aug 2019
Kabil
on 15 Dec 2025
0 votes
>> 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);
>>
Categories
Find more on Subplots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!