Plotting reflectance against time

I have plotted reflectance against wavelength using the following code, but now wish to plot reflectance against time. I have 2400 files each containing a complete spectrum at a certain point in time. There is 0.5 secs between each spectrum being recorded. I wish for the reflectance (2nd column) to be averaged for each spectrum
dirname='E:\Blue Wool Reflectance\';
head=[dirname 'BW Reflectance00000' '.txt'];
A=load(head);
wv=A(:,1);
R0=A(:,2);
mean(R0(200:1400))
timedifference=0.5
R=zeros(2048,2400);
for i=1:9
head=[dirname 'BW Reflectance0000' num2str(i) '.txt'];
A=load(head);
R(:,i)=A(:,2);
end
for i=10:99
head=[dirname 'BW Reflectance000' num2str(i) '.txt'];
A=load(head);
R(:,i)=A(:,2);
end
for i=100:999
head=[dirname 'BW Reflectance00' num2str(i) '.txt'];
A=load(head);
R(:,i)=A(:,2);
end
for i=1000:2400
head=[dirname 'BW Reflectance0' num2str(i) '.txt'];
A=load(head);
R(:,i)=A(:,2);
end
i=200;
figure(1)
plot(wv,R(:,i),'r')
xlim([400 700])
xlabel('\lambda')
ylabel('Reflectance%')

 Accepted Answer

If you load it into a 2-D array, R, where each row is a spectrum taken at some time, then you're going to have to have another array, acquisitionTimes, that contains the time each spectrum/row was taken at. Then you can pick a particular wavelength and plot it vs. times, something like
wavelength = 15; % Let's look at the wavelength in column 15 over time.
plot(acquisitionTimes, R(:, wavelength), 'b-', 'LineWidth', 2);
grid on;
xlabel('Time', 'FontSize', 20);
caption = sprintf('Reflectance at wavelength %d', wavelength);
ylabel(caption, 'FontSize', 20);

More Answers (1)

Adam - in the future, please format your code so that it is readable. I have done this for you, but all you need to do is to highlight the code and press the {}Code button.
So presumably your above code shows that every column of R is the reflectance for a particular spectrum. To calculate the average, use mean as
avgR = mean(R);
which you can then plot against time (which I don't think is the wv wavelength from above).

1 Comment

Thanks for the tip. First time poster will remember for future.
My issue is how to create an array of time values that corresponds to each of the spectrums I recorded so that the mean from each spectrum is plotted against the time the spectrum was recorded. This information is not contained within the data so must be entered 'manually'

Sign in to comment.

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!