Clear Filters
Clear Filters

Plotting selective Excel Data in Matlab

2 views (last 30 days)
Ali Akber
Ali Akber on 18 Jan 2016
Answered: Titus Edelhofer on 18 Jan 2016
I have two small issues:
1: I want to use the excel sheet name as a tittle name of each plotted figure. 2: If the number of figures are more that the array given in subplot it generates error. e.g. if i=10 and the subplot array is 3x2 then it only generate the pdf with 6 figures and doesn't generate the the remaining 4.
I am totaly new to matlab . please ignore if the question sounds stupid.
Here is my code clear; clc; XLfile = dir; number_of_files = length(XLfile); index = 3;
for index = 3:number_of_files
filename = XLfile(index).name;
for i=1:10
x=xlsread(filename,i,'C2:C10000');
y=xlsread(filename,i,'D2:D10000');
subplot(3,2,i);
plot(x,y,'b')
xlabel('Shear strain (%)','FontSize', 8)
ylabel('Shear stress ratio (\tau^{\prime}/\sigma_{vo}^{\prime})','FontSize', 8)
title(filename(1:end-4))
set(gcf, 'PaperPosition', [0 0 5 8]);
set(gcf, 'PaperSize', [5 8]);
saveas(gcf,[filename(1:end-4),'pdf'])
end
figure
end

Answers (1)

Titus Edelhofer
Titus Edelhofer on 18 Jan 2016
Hi,
I'm not sure where the problem with the title is, because calling
title(filename(1:end-4))
should work.
Regarding the problem with 6 subplots and the loop of 10: it is not clear to me what you expect? You use subplot(3,2,i), so that the output looks like
[plot1] [plot2]
[plot3] [plot4]
[plot5] [plot6]
But your loop runs from 1 to 10. So when the loop is at 7, what do you expect to happen?
You could e.g. use subplot(4,3,i), this way you would see all 10 plots ...
Titus

Community Treasure Hunt

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

Start Hunting!