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!