Read data from Excel

3 Ansichten (letzte 30 Tage)
Anton Vernytsky
Anton Vernytsky am 24 Jan. 2022
Kommentiert: Marcus Glover am 25 Jan. 2022
Hello,want to plot data from excel,I wrote a code and its works but its only for the first column and i have 98 of them.
My question i can use "for" loop for example to make me all the 98 plots,i will write here my code and the plot example.
The wavelength need to stay the same range but i need that the reflection will go to C,D,E,F.... columns.
Thank you for your help.
clear all;
clc;
Wavelength = xlsread('Calcite.xlsx','A6:A2156');
reflection = xlsread('Calcite.xlsx','B6:B2156');
lmin = islocalmin(reflection,"MinSeparation",150);
figure;
plot(Wavelength,reflection,Wavelength(lmin),reflection(lmin),'ro')
title('(111b Sample) Relative Reflectance--Wavelength')
xlabel('Wavelength[nm]')
ylabel('Relative Reflectance')
grid on
grid minor

Akzeptierte Antwort

Marcus Glover
Marcus Glover am 24 Jan. 2022
Bearbeitet: Marcus Glover am 24 Jan. 2022
Yes, you can do this, but you will need to read in the entire excel file (or at least the entire dataset) first. Then just define what you need. You are only reading in one reflection column (B) of your excel sheet.
xlsdata=xlsread('Calcite.xlsx'); %reads entire file
Wavelength=xlsdata(6:2156,1);
for i=1:98 %or however many columns you need
reflection=xlsdata(6:2156,i+1); %starts with 2nd column, will go to number 99
figure(i)%to generate a new figure each time- this will make 98 plots
%do your plotting
end
  3 Kommentare
Anton Vernytsky
Anton Vernytsky am 25 Jan. 2022
Thank you,it works ! Funny but my i7 and 8GB RAM cant run 95 figuers and one. I will do it 20 plots each time.
Marcus Glover
Marcus Glover am 25 Jan. 2022
Yeah, I was going to say it may not be a good idea to make 98 figures at once- not sure exactly why but figures are resource intensive and really slow things down. I usually suppress them and save them automatically then open them individually if I actually need to. No matter how you slice it, 98 fiugures is a lot!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Data Import and Analysis finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by