I have 2 columns, i want to find the maximum in the second column and then know what value it is next to on the first column

Hello. I have two columns that are 1221 rows long. The absorbance is on the first column and the wavelength on the second column. I want to find the maximum value for wavelength between 651:1221. Then i want to know the value of the absorbance next to it. When i know the value of that absorbance i need the absolute value of that absorbance subtracted by 520. How do I do this? Thanks for your help!

Antworten (2)

Generate data
M = rand(1221,2)*1000;
Find max value and it's index in rows 651 to 1221 in the 2nd column of M.
[maxvalue, index] = max(M(651:1221,2))
maxvalue = 999.2946
index = 488
Look at the first column value at that specific row. Then take the absolute value and subtract 520.
Answer = abs(M(index+650,1))-520
Answer = 319.0898

5 Kommentare

Thank you!
so i have below in bold where i am trying to normalize it. how can i redo the data to have the new absorbance? the rest is me trying to make the error bars but i am not sure if i am doing it right
k = 1:length(data_set)
data= data_set{k}
absorbance= data(:, 2)/(max(data(651:1221, 2)));
wavelength= data(:, 1);
[pk, loc, w, p]= findpeaks(absorbance, wavelength, "MinPeakProminence", 0.08);
[maxvalue, index] = max(data(651:1221,2));
peak_520 = abs(data(index+650,1))-520;
sens_shifted_peak= [sens_shifted_peak, peak_520];
prom= [p(end), prom];
width= [w(end), width];
end
sens_shifted_peak_data{i}= sens_shifted_peak;
CI=ConInterval(peak_520);
sens_peak_shift_data_520= [sens_peak_shift_data_520; [mean(peak_520, 2) std(peak_520,0,2) CI(1) CI(2) CI(3) CI(4)]];
end
function data= ConInterval(x)
SEM = std(x,0,2)/sqrt(length(x));
ts = tinv([0.05 0.95],length(x)-1);
CI_info = mean(x,2) + (ts*SEM);
data= [SEM ts(2) CI_info(1) CI_info(2)];
end
In your post, you stated, "The absorbance is on the first column and the wavelength on the second column". In the bolded line, it looks like you are defining the absorbance based on the second column.
You're right. wavelength is the first column, absorbance the second column. id like to replace the absorbance with the normalized absorbance.
Generate data
M = rand(1221,2)*1000;
Did you want to normalize based on the absorbance at the max wavelength?
Find max value and it's index in rows 651 to 1221 in the 2nd column of M.
[maxvalue, index] = max(M(651:1221,2))
maxvalue = 999.5113
index = 186
absorbance_at_max_wavelength = M(index+650,1)
absorbance_at_max_wavelength = 753.0649
norm_absorbance = M(:,1)/absorbance_at_max_wavelength;
Look at the first column value at that specific row. Then take the absolute value and subtract 520.
Answer = abs(norm_absorbance(index+650,1))-520
Answer = -519
Or did you want to normalize based on the max absorbance?
M(:,1) = M(:,1)/max(M(:,1))
M = 1221×2
0.2738 682.4881 0.6873 114.3255 0.8356 60.1602 0.1472 987.4319 0.5303 475.9494 0.0270 282.6909 0.7116 464.6401 0.5602 833.6767 0.4480 193.7245 0.8933 702.8031
Answer = abs(M(index+650,1))-520
Answer = -519.2466
So i want the data to be normalized like this absorbance= data(:, 2)/(max(data(321:1221, 2)));
i want to leave the first column the same in data but replace the second column with the data from absorbance= data(:, 2)/(max(data(321:1221, 2)));
i want to only change the second column in data to be absorbance= data(:, 2)/(max(data(321:1221, 2)));
but keep the first column the same and then do the part that you had initially.

Melden Sie sich an, um zu kommentieren.

% Pretend data
aw = rand(1221,2) + 250;
% Max 2nd col in range, with index
[maxW,idx] = max(aw(651:1221,2));
% Absorbance for that value of W
aAtMaxW = aw(650+idx,1);
% Subtract 520 and take absolute value
a520 = abs(aAtMaxW - 520)
a520 = 269.6571

4 Kommentare

@Kevin Holly and I posted nearly identical solutions within a couple minutes of each other.
Note that we assumed different things about when to apply the absolute value function. Take care on that point.
Thank you!
so i have below in bold where i am trying to normalize it. how can i redo the data to have the new absorbance? the rest is me trying to make the error bars but i am not sure if i am doing it right
k = 1:length(data_set)
data= data_set{k}
absorbance= data(:, 2)/(max(data(651:1221, 2)));
wavelength= data(:, 1);
[pk, loc, w, p]= findpeaks(absorbance, wavelength, "MinPeakProminence", 0.08);
[maxvalue, index] = max(data(651:1221,2));
peak_520 = abs(data(index+650,1))-520;
sens_shifted_peak= [sens_shifted_peak, peak_520];
prom= [p(end), prom];
width= [w(end), width];
end
sens_shifted_peak_data{i}= sens_shifted_peak;
CI=ConInterval(peak_520);
sens_peak_shift_data_520= [sens_peak_shift_data_520; [mean(peak_520, 2) std(peak_520,0,2) CI(1) CI(2) CI(3) CI(4)]];
end
function data= ConInterval(x)
SEM = std(x,0,2)/sqrt(length(x));
ts = tinv([0.05 0.95],length(x)-1);
CI_info = mean(x,2) + (ts*SEM);
data= [SEM ts(2) CI_info(1) CI_info(2)];
end
I'm not sure what "redo the data to have the new absorbance" means. Do you want to divide all the absorbance values by this value we helped you calculate? If so, then
data(:,1) = data(:,1)/peak_520
I misspoke in my first question. The wavelength is the first column, absorbance the second column. id like to replace the absorbance with the normalized absorbance in data to then calculate what you had initially answered.

Melden Sie sich an, um zu kommentieren.

Gefragt:

am 22 Mär. 2023

Bearbeitet:

am 22 Mär. 2023

Community Treasure Hunt

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

Start Hunting!

Translated by