How to create a matrice from selected rows from other matrices
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Jonathan Demmer
el 18 de Mzo. de 2021
Comentada: Rik
el 18 de Mzo. de 2021
Hello all,
I would like to select a specific row (4187) from n matrices (n =20) and add these rows in a new matrice. I wrote the code below, I thought that every file loaded will add the line selected in the new matrice. However after the first iteration the matrice holy_lat_final becomes a matrice (1,1436) instead of staying (20,1436), and so the second iteration cant be done... can someone help me pelase?
file_lat_1 = 'October_01_2014_surface_lat_##.mat';
file_lon_1 = 'October_01_2014_surface_lon_##.mat';
Holy_lat_final = zeros (20,1436);
Holy_lon_final = zeros (20,1436);
n = 20; % number particles release per site
for i = 1:n % particle release
file_lat_1(29:30)=sprintf('%02.0f',i);
file_lon_1(29:30)=sprintf('%02.0f',i);
Holy_lat = load(file_lat_1);
Holy_lon = load(file_lon_1);
Holy_lat_final = Holy_lat_final(i,:) + Holy_lat.lat(4187,1:1436);
Holy_lon_final = Holy_lon_final(i,:) + Holy_lon.lon(4187,1:1436);
end
0 comentarios
Respuesta aceptada
Rik
el 18 de Mzo. de 2021
You overwrote the entire variable. See the edits I made to your code.
file_lat_1_fmt = 'October_01_2014_surface_lat_%02.0f.mat';
file_lon_1_fmt = 'October_01_2014_surface_lon_%02.0f.mat';
n = 20; % number particles release per site
Holy_lat_final = zeros (n,1436);
Holy_lon_final = zeros (n,1436);
for i = 1:n % particle release
file_lat_1(29:30)=sprintf(file_lat_1_fmt,i);
file_lon_1(29:30)=sprintf(file_lon_1_fmt,i);
Holy_lat = load(file_lat_1);
Holy_lon = load(file_lon_1);
Holy_lat_final(i,:) = Holy_lat.lat(4187,1:1436);
Holy_lon_final(i,:) = Holy_lon.lon(4187,1:1436);
end
2 comentarios
Rik
el 18 de Mzo. de 2021
You're welcome. If my answer solved your issue, please consider marking it as accepted answer, if not, feel free to post a comment with your remaining issues.
Más respuestas (0)
Ver también
Categorías
Más información sobre Particle Swarm en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!