How to plot multiple curves without usnig a for loop?
Show older comments
I was tryiinig to plot my graphs with multiple curves on the same graph. It didnt work until I have added the 'for i=1:1:length(wpp)' and added p{i} next to all the variables withiin plot(x,y). I am not sure why must I use the for loop and is there anyway I can just plot the graphs without using it?
for i = 1:1:length(wpp)
subplot(2,2,1);plot(wpp{i},temppp{i});hold on;grid;ylabel('T(K)');xlabel('w(1000kg)');title('Temperature');
subplot(2,2,2); plot(wpp{i},yapp{i});hold on;grid;ylabel('yC (%)'); xlabel('w(1000kg)');title('Mole fraction of C');
subplot(2,2,3);plot(wpp{i},ppp{i});hold on; grid;ylabel('P (bar)');xlabel('w(1000kg)');title('Pressure');
subplot(2,2,4);plot(wpp{i},ycpp{i});hold on;grid;ylabel('yC (%)');xlabel('w(1000kg)');title('Mole fraction of C');
sgtitle('Case B: Adiabatic PBR with Interstage cooling P = 50 bar');
t{i} = num2str(temppp{i}(1));
end
1 Comment
M.B
on 10 Dec 2021
It depends on how you organise your data.
What size are wpp and wpp{i}? (I assume that wpp, temppp, yapp, ppp, and ycpp are or similar size and structure)
Answers (1)
MATLAB will treat columns of data in a matrix as series. If you organize your "curves" so that each is in its own column, you should be able to plot using plot(wpp,tempp).
It appears your data is in a cell since you are indexing using curly braces. Change it to a matrix.
x = rand(5,3);
y = rand(5,3)*5;
plot(x,y)
Categories
Find more on Graphics Object Properties 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!