ploting Multiple graphs from multiple excel sheets using Matlab 2018

22 visualizaciones (últimos 30 días)
[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!

Respuestas (1)

Walter Roberson
Walter Roberson el 26 de Ag. de 2021
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 comentarios
Najwa Abdel Latif
Najwa Abdel Latif el 26 de Ag. de 2021
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..
Walter Roberson
Walter Roberson el 26 de Ag. de 2021
These days replace the xlsinfo call with https://www.mathworks.com/help/matlab/ref/sheetnames.html
sheets = sheetnames(filename);
and remove the isempty(status) test.

Iniciar sesión para comentar.

Categorías

Más información sobre Printing and Saving en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by