Read & Plot to compare Data in Multiple SpreadSheets
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Raghu Vamsi
el 9 de Oct. de 2019
Comentada: Turlough Hughes
el 10 de Oct. de 2019
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 comentarios
Respuesta aceptada
Turlough Hughes
el 9 de Oct. de 2019
Editada: Turlough Hughes
el 9 de Oct. de 2019
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 comentarios
Turlough Hughes
el 10 de Oct. de 2019
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().
Más respuestas (0)
Ver también
Categorías
Más información sobre Data Import from MATLAB en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!