ploting Multiple graphs from multiple excel sheets using Matlab 2018

23 次查看(过去 30 天)
[status,sheets,xlFormat]=xlsfinfo('Majorfaults_300m_10profiles.xlsx')
A=cell2mat(sheets)
for idx_cell = 1:size(sheets,1) out.(sheets{idx_cell})={}; end
A = cell2mat(sheets(1))
A= convertCharsToStrings(cell2mat(sheets(1)))
This is what I have tried so far, but my sheets are not being converted into matrices! I need to do that and then from each sheet plot a graph with column A vs. Column B E F D ..
and repeat for all sheets I have.
At the end I need 68 Figures from 68 sheets.
Thank you!

回答(1 个)

Walter Roberson
Walter Roberson 2021-8-26
filename = 'Majorfaults_300m_10profiles.xlsx';
[status, sheets] = xlsfinfo(filename);
if isempty(status); error('Cannot find sheets in file "%s"', filename); end
out = struct();
for idx_cell = 1:size(sheets,1)
thissheet = sheets{idx_cell};
thisdata = readmatrix(filename, 'sheet', thissheet);
out.(thissheet) = thisdata;
fig = figure();
ax = axes(fig);
plot(ax, thisdata(:,1), thisdata(:,[2 5 6 4]));
legend(ax, {'B', 'E', 'F', 'D'});
xlabel(ax, 'A');
title(ax, thissheet);
end
This code reads and plots, and also stores the data in the struct out .
One figure is created for each sheet.
... That's a lot of figures. Wouldn't you prefer to write the result as images or something like that? Maybe a movie?
  2 个评论
Najwa Abdel Latif
Najwa Abdel Latif 2021-8-26
Thank you so Much for you reply.
The If condition in the code returns error
... if isempty(status); error('Cannot find sheets in file "%s"', filename); end ...
and if I exclude it from the code and run it i recieve the following error msg
Error in internet (line 10)
thissheet = sheets{idx_cell};
I am not sure where the problem is.. mean while I have developed a code where I got the data from my excel file and was able to plot it.
please see below,
...........................................................
%%
[status,sheets,xlFormat]=xlsfinfo('Majorfaults_300m_10profiles.xlsx')
for k=1:numel(sheets)
data{k}=xlsread('Majorfaults_300m_10profiles.xlsx',sheets{k});
end
for i = 2:6
plot( data{1}(:,1),data{1}(:,i))
hold on
end
%%
...........................................................
this code worked.. I just can't make a nother loop that plots all at once. in my code I need to write the plotting comand 68 times..

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Printing and Saving 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by