How to create a matrice from selected rows from other matrices

1 回表示 (過去 30 日間)
Jonathan Demmer
Jonathan Demmer 2021 年 3 月 18 日
コメント済み: Rik 2021 年 3 月 18 日
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

採用された回答

Rik
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 件のコメント
Jonathan Demmer
Jonathan Demmer 2021 年 3 月 18 日
Perfect!! thank you very much!!!
Rik
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 ExchangeStatistics and Machine Learning Toolbox についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by