How to create a matrice from selected rows from other matrices
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Rik
2021-3-18
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 个评论
Rik
2021-3-18
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Particle Swarm 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!