I have a loop but only the last value saves
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
i want to see the individual peak shifts for 520. i see it as a weird output with disp but i want it in my variables not an output in the command window. the bolded line is what i want to see all the values for before the mean. for sens_peak_shift_data_520 i only see the means there but i do not want to alter that because i am graphing from that variable. please help!
for i= 1:length(sens_legend)
data_set= sens_legend{i};
peak_520=[]; prom=[]; width=[]; peak_260=[];
sens_shifted_peak=[];
for k = 1:length(data_set)
data= data_set{k};
absorbance= data(:, 2)/(max(data(321:1221, 2)));
wavelength= data(:, 1);
data_n = [wavelength, absorbance];
[pk, loc, w, p]= findpeaks(absorbance, wavelength, "MinPeakProminence", 0.08);
[maxvalue, index] = max(data_n(651:1221,2));
peak_520 = [abs(data_n(index+650,1))-520, peak_520];
disp(peak_520)
sens_shifted_peak= [sens_shifted_peak, peak_520];
end
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)]];
Risposte (1)
Dinesh
il 5 Apr 2023
Hi Chelsie.
It seems that you want to store the individual peak shifts for 520 in a variable rather than displaying them in the command window using "disp". To achieve this, you can create an additional variable to store the peak shifts for each dataset in "sens_legend". I added a new variable named "all_peak_shifts_520" that will store the peak shifts for all datasets.
You can create the "all_peak_shifts_520" variable as an empty cell array before the main for loop:
all_peak_shifts_520 = {};
After the inner for loop, you can store the peak shifts for the current dataset.
all_peak_shifts_520{end+1} = peak_520;
Now, you can access the individual peak shifts for 520 for each dataset in the "sens_legend" by indexing "all_peak_shifts_520". For example, to access the peak shifts for the first dataset, use "all_peak_shifts_520{1}". This will not affect the "sens_peak_shift_data_520" variable.
3 Commenti
Dinesh
il 7 Apr 2023
Hi Chelsie. I'm not able to understand why this is happening. But, the code will store all the peak shifts for every item in "sens_legend". Since the inner loop calculates all the peak shifts for each item in "sens_legend", the following line after the inner for loop will store that peak shift in a new array.
all_peak_shifts_520{end+1} = peak_520;
Either the place where you included this piece of code is wrong or the sizes of "sens_legend" and "data_set" might just be 1 in this case since its showing 1x1 cell in the workspace.
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!