Saving matrices as separate files in for loop

4 ビュー (過去 30 日間)
Anita Sinha
Anita Sinha 2021 年 4 月 27 日
コメント済み: Anita Sinha 2021 年 4 月 27 日
Hello. I have a data_matrix of size 200 x 200x 50, where 50 is the total number of subjects and adj_matrix of size 200 x 200 x 50. I am trying to iterate over each data_matrix(:, :, i) in data_matrix and multiply it with the corresponding adj_matrix(:, :, i). I want to save the final matrix as a separate file in a directory.
Example code:
for i = 1:size(data_matrix,3) % = 50
transform = new(:, :, i)*data_matrix(:, :, i)
save(['output_dir/transformed_' num2str(i) '.mat'], i)
end
but I get the error, "Error using save. Must be a string scalar or character vector."
The final outputs should be separate matrices in which each file is called transformed_1, transformed_2, etc.
Could someone help with this?

採用された回答

Clayton Gotberg
Clayton Gotberg 2021 年 4 月 27 日
You need to specify the variables to be saved as strings or characters, too.
save(['output_dir/transformed_' num2str(i) '.mat'], 'transform')
  1 件のコメント
Anita Sinha
Anita Sinha 2021 年 4 月 27 日
Oh that's true, I should have caught that. Thank you!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Import and Management についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by