Hold on not working when plotting graph from a cell array

Hello all,
I have extracted several sheets of data from an excel file (Cellulose.xlsx) into a cell array (Cellulose) and I wanted to plot the data of each sheet on the same graph. However the graph only shows the last plot even though i have used the hold on function. Can someone suggest a solution? Thanks!
Cellulose='Cellulose.xlsx';
heating_rate={'10kmin','20kmin','30kmin','40kmin','50kmin',...
'60kmin','70kmin','80kmin','90kmin','100kmin'};
n=length(heating_rate);
data=cell(n,1);
for idx=1:n
data{idx}=xlsread(Cellulose, heating_rate{idx});
end
figure(1); hold on;
for i=1:n
x1=data{n,1}(:,1)+273.15;
y1=data{n,1}(:,3);
plot(x1,y1);
end
hold off;

1 件のコメント

Matt J
Matt J 2017 年 8 月 19 日
Attach the data{} cell in a .mat file so that we can try it.

サインインしてコメントする。

 採用された回答

Star Strider
Star Strider 2017 年 8 月 19 日
編集済み: Star Strider 2017 年 8 月 19 日

3 投票

This works:
figure(1)
hold on
for i=1:n
x1=data{i,1}(:,1)+273.15;
y1=data{i,1}(:,3);
plot(x1,y1);
end
hold off

5 件のコメント

Jo 5
Jo 5 2017 年 8 月 19 日
Thanks for your reply, but it isnt working :/
Star Strider
Star Strider 2017 年 8 月 19 日
Your subscripts need to be with respect to ‘i’, not ‘n’. See my edited Answer.
Jo 5
Jo 5 2017 年 8 月 19 日
Thanks Star!!! it works!! :)
Star Strider
Star Strider 2017 年 8 月 19 日
編集済み: Star Strider 2017 年 8 月 19 日
My pleasure!
Image Analyst
Image Analyst 2017 年 8 月 19 日
Then please vote for him and "Accept this answer" so he gets credit for it.

サインインしてコメントする。

その他の回答 (0 件)

質問済み:

2017 年 8 月 19 日

編集済み:

2017 年 8 月 19 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by