I have sequential x_y grid text files each with column 1 as wavenumber and column 2 intensity outputs. I am looking to extract position (0_0, 0_1, 0_2 etc), peak position (wavenumber), peak intensity as a 3 column matrix from my nested for loop.
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Currently the code I have is: file_address = 'C:\Users\Desktop\.....\1.5step 45mins\run 51 extracted from labspec\'
x_grid = [0:1:1];
y_grid = [0:1:5];
run_name = 'run51__'
x_size = length(x_grid);
y_size = length(y_grid);
x_y = x_size*y_size;
output = zeros(x_y, 2);
for i = 1:x_size
for j = 1: y_size
a=x_grid(i);
b=y_grid(j);
run_number1 = strcat(num2str(a(i)),'_',num2str(b(j)));
run_number2 = strcat(run_name,run_number1);
address = strcat(file_address,run_number,'.txt'); %address 'C:\Users\....\..\..\run27_0_0.txt
run = (dlmread(address)); %open and read run27_0_0.txt
wavenumber = run(:,1);
intensity = run(:,2);
peakI= max(intensity);
pIind = find(peakI);
peak_wavenumber=wavenumber(pIind);
basically I want to extract per dlmread a matrix with [run_number1 peak_wavenumber peakI]
Any help would be greatly appreciated. I cant seem to get the syntax right for the nested for loop.
output(i,j) = output(run_number1 peak_wavenumber peakI)????
(I appreciate it is not indented properly here)
0 comentarios
Respuestas (1)
Faiz Gouri
el 17 de Ag. de 2017
I understand that you would like to read values from different files with similar syntax(wavenumber intensity), and store values corresponding to maximum intensity into a single matrix. In order to do so you can create an empty matrix with 3 columns and desired number of rows and update it row-by-row every time you read from the file.
results_matrix = zeros(x_y, 3);
...
...
for i = 1:x_size
....
....
results_matrix(i,:)= [run_number1 peak_wavenumber peakI]
end
Hope this helps!
0 comentarios
Ver también
Categorías
Más información sobre Data Type Conversion en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!