Hi everyone, I am working on some code and I am having issues. Every time I run the code instead of obtaining 5 unique figures, I get the same figure 5 times as my code reads all of the files but only plots the last one.
numfiles = 5;
mydata = cell(1, numfiles);
for i = 1:5
myfilename = sprintf('file%d.xlsx', i);
mydata{i} = xlsread('Base_01');
myfilename = sprintf('file%d.xlsx',i);
newdata{i} = xlsread('Hydrophone_01');
end
save('mydata.mat')
save('newdata.mat')
for i = 1:5 %why is it only plotting the last data set
thisfig = figure();
Data = mydata{1,i} (15005:21255,:);
subplot(3,1,1);
plot(Data(:,1),Data(:,2))
xlim([60 85])
title('Amplitude vs. Time for Base Data')
Code continues on further but I just shortened it here because this is the main issue I am having.
Thanks! Any help will be appreciated.

6 件のコメント

per isakson
per isakson 2018 年 10 月 29 日
編集済み: per isakson 2018 年 10 月 29 日
This code plots two diagrams on top of each other - as should be expected.
for ii = 1:2 %why is it only plotting the last data set
thisfig = figure();
Data(:,2) = randn( 17, 1 );
Data(:,1) = (1:17)';
subplot(3,1,1);
plot(Data(:,1),Data(:,2))
title('Amplitude vs. Time for Base Data')
end
Muhammad Akram
Muhammad Akram 2018 年 10 月 29 日
what does the randn do?
Also, what do you mean by plotting two diagrams on top of each other?
per isakson
per isakson 2018 年 10 月 29 日
編集済み: per isakson 2018 年 10 月 29 日
madhan ravi
madhan ravi 2018 年 11 月 4 日
don't close question which has answer
Muhammad Akram
Muhammad Akram 2018 年 11 月 4 日
The answer does not work.
madhan ravi
madhan ravi 2018 年 11 月 4 日
Did you upload your file?

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

回答 (1 件)

madhan ravi
madhan ravi 2018 年 10 月 29 日

0 投票

numfiles = 5;
mydata = cell(1, numfiles);
for i = 1:5
myfilename = sprintf('file%d.xlsx', i);
mydata{i} = xlsread('Base_01');
myfilename = sprintf('file%d.xlsx',i);
newdata{i} = xlsread('Hydrophone_01');
end
save('mydata.mat')
save('newdata.mat')
for i = 1:5 %why is it only plotting the last data set
thisfig = figure(i);
Data = mydata{1,i} (15005:21255,:);
subplot(3,1,1);
plot(Data(:,1),Data(:,2))
xlim([60 85])
title('Amplitude vs. Time for Base Data')
end

2 件のコメント

Muhammad Akram
Muhammad Akram 2018 年 10 月 29 日
I have tried that already. When I use
thisfig = figure(i);
I end up obtaining the same plot 5 times.
madhan ravi
madhan ravi 2018 年 10 月 29 日
Mind uploading your file?

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

カテゴリ

製品

質問済み:

2018 年 10 月 29 日

コメント済み:

2018 年 11 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by