Read & Plot to compare Data in Multiple SpreadSheets

15 ビュー (過去 30 日間)
Raghu Vamsi
Raghu Vamsi 2019 年 10 月 9 日
コメント済み: Turlough Hughes 2019 年 10 月 10 日
Hi,
I have multiple sheets in Excel file which is again created by matlab script. Iam running some iterations in matlab, so the variable names in each sheet of the excel file will same except for the data. I would like to compare the data of same variable in each sheet with a plot.
Could somebody help me with read the data on each sheet and plot them to compare in matlab.
Thanks
Raghu
  2 件のコメント
Ankit
Ankit 2019 年 10 月 9 日
how your code looks like? where you are facing problem?
Raghu Vamsi
Raghu Vamsi 2019 年 10 月 9 日
編集済み: Raghu Vamsi 2019 年 10 月 9 日
Hi Ankit,
Thanks for replying. To be frank, i have no code for this solution, I am trying to get help from the community. All i am doing right now is with Excel completely.
I am working on the code as i speak with you and it can read one sheet at a time and plot the data in that sheet.
I am not a matlab user.
a1 = xlsread('examplefile.xlsx','sheet1');
plot (a1(:,1),a1(:,2));
hold on
a1 = xlsread('examplefile.xlsx','sheet2');
plot (a1(:,1),a1(:,2));
hold on
a1 = xlsread('examplefile.xlsx','sheet3');
plot (a1(:,1),a1(:,2));
hold on
a1 = xlsread('examplefile.xlsx','sheet4');
plot (a1(:,1),a1(:,2));
hold off
This is what i have so far and i want to avoid writing so many lines. 4 sheets data is just an example as i have to work on more than 50 sheets with 10 - 20 columns each.

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

採用された回答

Turlough Hughes
Turlough Hughes 2019 年 10 月 9 日
編集済み: Turlough Hughes 2019 年 10 月 9 日
Hi Raghnu,
I reckon you should store your data in a structure and use dynamic fieldnames to have a fieldname corresponding to each sheet in your file. Try the following:
[~,sheet_name] = xlsfinfo('examplefile.xlsx')
for k = 1:numel(sheet_name)
[data, vnames{k}] = xlsread('examplefile.xlsx',sheet_name{k});
s.(sheet_name{k}) = array2table(data,'VariableNames',vnames{k});
end
To plot in a loop then you just do the following:
figure(), hold on
for c = 1:numel(sheet_name)
plot(s.(sheet_name{c}).(vnames{c}{1}),s.(sheet_name{c}).(vnames{c}{2}))
larray{c}=vnames{c}{2}
end
l=legend(larray)
set(l,'Interpreter','none')
If you wanted to look at results from an given sheet you just enter the following:
s.Sheet1
s.Sheet2
etc
  3 件のコメント
Turlough Hughes
Turlough Hughes 2019 年 10 月 10 日
No problem. Regarding your question, the function has two output arguments and I only wanted the second one. The tilda is just used to ignore the first output argument of xlsinfo().
Turlough Hughes
Turlough Hughes 2019 年 10 月 10 日
Also, if you are happy with this can you accept the answer.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Import from MATLAB についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by