How can I access different excel files and plot the data from each file on a single figure?

4 views (last 30 days)
Hi there,
I would like some assistance in accessing data from different excel files and then plotting the data from each of these files on a single figure.
Right now the code looks like this:
comparisons=input('How many graphs to plot?')
for i=1:comparisons
[a b c]=uigetfile('*xlsx','Select the Excel file')
[strain]=xlsread(a,'H1:H1000');
[stress]=xlsread(a,'J1:J1000');
figure (1)
hold on
plot(strain,stress,'b.')
xlabel('Strain')
ylabel('Stress')
legend(a)
hold off
i=i+1
end
I do not know how to include the name of all of the plots in the legend and I also do not know how to vary the plotting colour for each of the different plots. The number of plots that I require can vary from 1 plot on a certain figure to 5 plots on another figure.
Any help with this problem would be much appreciated

Answers (1)

Image Analyst
Image Analyst on 25 Oct 2014
To plot in blue:
plot(strain,stress,'b.')
To plot in red:
plot(strain,stress,'r-')
Other colors are 'y', 'w', 'k', 'c', 'm', 'g'. You can get more with the 'Color' option of plot() - see the help. To plot up to six plots on one figure, use subplot(2,3,n)

Community Treasure Hunt

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

Start Hunting!