Plot function into subplots
Mostra commenti meno recenti
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.
Risposta accettata
Più risposte (2)
KALYAN ACHARJYA
il 12 Ago 2019
Modificato: KALYAN ACHARJYA
il 12 Ago 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 Commento
Daniel Schmidt
il 12 Ago 2019
Kabil
il 15 Dic 2025
0 voti
>> 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);
>>
Categorie
Scopri di più su Subplots in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!