How to plot more than one graph on a single tile using tiledlayout?
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
I'm solving 17 species through ode45 (using a for loop with three different initial values). I want to plot all three solutions of a single species on one tile using tiledlayout. With the code I currently have it only plots the third iteration of each species. Could you please provide your expert advise? Thank you!
% Numerically finding the all-positive equilibrium point
% Remove the contents of the workspace
clear
% Set the initial time domain for integration
tstart=0;tend=150;
tspan=[tstart,tend];
y0 = [1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21];
for k = 1:length(y0)
[t,y] = ode45(@Chol_model3,tspan,[y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k)]);
end
tiledlayout(2,2)
nexttile
plot(t,y(:,3),'g','LineWidth', 1,'LineStyle','-');
title('B')
xlabel('Time')
ylabel('Species concentration')
nexttile
plot(t,y(:,4),'k','LineWidth', 1,'LineStyle','-');
nexttile
plot(t,y(:,5),'r','LineWidth', 1,'LineStyle','-');
nexttile
plot(t,y(:,6),'b','LineWidth', 1,'LineStyle','-');

채택된 답변
I cannot run the posted code, however it is definitely possible to plot more than one series on a specific tile using the hold function —
t = 0:10;
tiledlayout(1,2)
nexttile
plot(t, rand(1,11))
hold on
plot(t, randn(1,11))
hold off
nexttile
plot(t, rand(1,11))
hold on
plot(t, randn(1,11))
hold off

.
댓글 수: 13
My apologies, the ode45 solver uses the Chol_model3.m file with code posted below. (I have not been able to combine these two files into one script file yet).
function dydt = Chol_model3(t,y)
%Read in the parameters from a file
%Chol_parameters
theta=10;
eta=0.01;
mu=5;
gamma=1;
p1=1;
p2=0.8;
k1=0.08;
k2=0.05;
k3=0.1;
k4=0.5;
k5=0.08;
k6=0.01;
k7=0.01;
k8=0.05;
k9=0.1;
k10=10;
k11=0.1;
k12=1;
k13=1;
k14=0.5;
k15=1;
k16=1;
k17=0.01;
k18=1;
R1=0.1;
R2=0.1;
C=y(1);Bc=y(2);B=y(3);Ce=y(4);S=y(5);L=y(6);Ldl=y(7);H=y(8);I=y(9);Cp=y(10);
Cm=y(11);E=y(12);O=y(13);Io=y(14);X=y(15);Xo=y(16);A=y(17);D=y(18);
eqn1=theta*Ce-p1*B*C;
eqn2=p1*B*C-eta*Bc*I;
eqn3=mu-p1*B*C-p2*B;
eqn4=k1*Cp+k3*E-k2*Ce-k4*Ce-theta*Ce+k5*H;
eqn5=p2*B-k9*S;
eqn6=k9*S-k6*L-k15*L*D;
eqn7=k6*L-k7*Ldl;
eqn8=k9*S-k5*H-k16*Io*H;
eqn9=k9*S-k11*I*O-k17*I-eta*Bc*I;
eqn10=k2*Ce+k7*Ldl-k1*Cp-k8*Cp-R1;
eqn11=k8*Cp-k10*Cm - R2;
eqn12=k4*Ce-k3*E-k18*A*E;
eqn13=k10*Cm-k11*I*O-k12*X*O;
eqn14=k11*I*O-k16*Io*H;
eqn15=gamma-k12*X*O;
eqn16=k12*X*O-k13*Xo-k14*Xo;
eqn17=k13*Xo-k18*A*E;
eqn18=k14*Xo-k15*L*D;
dydt=[eqn1; eqn2; eqn3; eqn4; eqn5; eqn6; eqn7; eqn8; eqn9; eqn10; eqn11; eqn12;
eqn13; eqn14; eqn15; eqn16; eqn17; eqn18];
Without the tiledlayout code, I can get the three graphs to show:
y0 = [1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21];
for k = 1:length(y0)
[t,y] = ode45(@Chol_model3,tspan,[y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k)]);
plot(t,y(:,3),'g','LineWidth', 1,'LineStyle','-');
title('B')
xlabel('Time')
ylabel('Species concentration')
end

If I add the tiledlayout code it only plots one graph. I'm not sure why?
y0 = [1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21];
for k = 1:length(y0)
[t,y] = ode45(@Chol_model3,tspan,[y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k)]);
tiledlayout (2,2)
nexttile
plot(t,y(:,3),'g','LineWidth', 1,'LineStyle','-');
hold on
title('B')
xlabel('Time')
ylabel('Species concentration')
end
hold off

I am still getting used to tiledlayout since I do not use it often.
The first of these draws a plot in each tile, however when I run them together, the second tiledlayout call clears the first set, so I leave the first set to you to experiment with. (This is unlike the subplot function that can create separate subplots in a single figure window. There might be a way to do that with tiledlayout, however I cannot find any documentation for it.) Run them separately to see the results of each.
The problem is that your original code only plots one integration in each tile, similar to my first set here. So the hold call has no effect.
The second creates a single tile and plots all the differential equation solutions in it using hold.
I am not certain what you are doing, however it is definitely possible to plot multiple series in a single tile using hold. It would certainly be possible to do that here, except the code you posted onlly plots one column of the differential equation integration in each iteration of the for loop.
% With 'tiledlayout' & Three Axes —
tspan = [0 150];
% y0 = [1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21];
tiledlayout(3,1)
y0 = 1:10:21;
for k = 1:length(y0)
y0k = ones(1,18)*y0(k);
% [t,y] = ode45(@Chol_model3,tspan,[y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k)]);
[t,y] = ode45(@Chol_model3,tspan,y0k);
nexttile
plot(t,y(:,3),'g','LineWidth', 1,'LineStyle','-');
grid
title('B')
xlabel('Time')
ylabel('Species concentration')
end
% With 'tiledlayout' & One Axes —
tspan = [0 150];
% y0 = [1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21 1:10:21];
tiledlayout(1,1)
nexttile
hold on
y0 = 1:10:21;
for k = 1:length(y0)
y0k = ones(1,18)*y0(k);
% [t,y] = ode45(@Chol_model3,tspan,[y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k) y0(k)]);
[t,y] = ode45(@Chol_model3,tspan,y0k);
plot(t,y(:,3),'g','LineWidth', 1,'LineStyle','-');
grid
title('B')
xlabel('Time')
ylabel('Species concentration')
end
hold off

function dydt = Chol_model3(t,y)
%Read in the parameters from a file
%Chol_parameters
theta=10;
eta=0.01;
mu=5;
gamma=1;
p1=1;
p2=0.8;
k1=0.08;
k2=0.05;
k3=0.1;
k4=0.5;
k5=0.08;
k6=0.01;
k7=0.01;
k8=0.05;
k9=0.1;
k10=10;
k11=0.1;
k12=1;
k13=1;
k14=0.5;
k15=1;
k16=1;
k17=0.01;
k18=1;
R1=0.1;
R2=0.1;
C=y(1);Bc=y(2);B=y(3);Ce=y(4);S=y(5);L=y(6);Ldl=y(7);H=y(8);I=y(9);Cp=y(10);
Cm=y(11);E=y(12);O=y(13);Io=y(14);X=y(15);Xo=y(16);A=y(17);D=y(18);
eqn1=theta*Ce-p1*B*C;
eqn2=p1*B*C-eta*Bc*I;
eqn3=mu-p1*B*C-p2*B;
eqn4=k1*Cp+k3*E-k2*Ce-k4*Ce-theta*Ce+k5*H;
eqn5=p2*B-k9*S;
eqn6=k9*S-k6*L-k15*L*D;
eqn7=k6*L-k7*Ldl;
eqn8=k9*S-k5*H-k16*Io*H;
eqn9=k9*S-k11*I*O-k17*I-eta*Bc*I;
eqn10=k2*Ce+k7*Ldl-k1*Cp-k8*Cp-R1;
eqn11=k8*Cp-k10*Cm - R2;
eqn12=k4*Ce-k3*E-k18*A*E;
eqn13=k10*Cm-k11*I*O-k12*X*O;
eqn14=k11*I*O-k16*Io*H;
eqn15=gamma-k12*X*O;
eqn16=k12*X*O-k13*Xo-k14*Xo;
eqn17=k13*Xo-k18*A*E;
eqn18=k14*Xo-k15*L*D;
dydt=[eqn1; eqn2; eqn3; eqn4; eqn5; eqn6; eqn7; eqn8; eqn9; eqn10; eqn11; eqn12;
eqn13; eqn14; eqn15; eqn16; eqn17; eqn18];
end
.
Thanks so much, I'll experiment with the examples you provided!
I had a go at using subplot too but could not get it to work. Would that perhaps be another option to explore further?
My main opjective is to plot each species with its associated graphs in a seperate tile.
Star Strider
2022년 4월 5일
편집: Star Strider
2022년 4월 5일
My pleasure!
‘I had a go at using subplot too but could not get it to work. Would that perhaps be another option to explore further?’
Yes. I have no specific preference for subplot, tiledlayout, or stackedplot. They each have properties that work best in specific applications.
‘My main opjective is to plot each species with its associated graphs in a seperate tile.’
Any of the three options that I mentioned would work for that. You need to decide on which is best. Regardless, I will do what I can to help you to get the plots working as you want them to work.
.
The tiledlayout with one axis works perfect, thank you!

As always, my pleasure!
I did not ask this before because it was not relevant, however just out of curiosity, what are you modeling?
Cellular cholesterol homeostasis - part of my PhD.
Fascinating!
Is this something I can look forward to reading about in Science or the NEJM?
Yep, hoping to send to the Journal of The Royal Society Interface very soon!
Getting it published in the JRS is impressive! I’d appreciate a link to it. It would be nice to at least be able to read the abstract. Unless it’s open-access, I likely won’t be able to read the entire article.
Hopefully it will be accepted! I'll keep you posted.
Thank you!
If you also send it to me as an email through my profile page, please provide a context so I’ll know what it refers to, in addition to including a link to this thread. If it’s just a link, I’ll probably not recognise it, and I’m averse to clicking on uinknown links.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Axes Appearance에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
