Plot function into subplots
이전 댓글 표시
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.
채택된 답변
추가 답변 (2개)
KALYAN ACHARJYA
2019년 8월 12일
편집: KALYAN ACHARJYA
2019년 8월 12일
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:

Kabil
2025년 12월 15일
0 개 추천
>> 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);
>>
카테고리
도움말 센터 및 File Exchange에서 Subplots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!