How do I add an additional matrix to be a variable in multpile matfiles?

2 ビュー (過去 30 日間)
KuanTing Wu
KuanTing Wu 2022 年 3 月 24 日
コメント済み: KuanTing Wu 2022 年 4 月 6 日
Hello! I have some matfiles to analysis and I have to add a new matrix to be a variable in one file. Like the below images show, I have to add an additional matrix 'lab' to the '0631312_s1.mat' (the second image), make it same like '0631312_1.mat' (the first image) and the matrix is a 512x512 null-matrix, like the third image.
I know we can use function zeros(n) to build a n x n null matrix, but what should I do to assign an additional matrix to be a variable in multiple matfiles automatically? Please suggest and thank you for helping me!

採用された回答

Biral Pradhan
Biral Pradhan 2022 年 3 月 29 日
I understand, you want to append an additional matrix as a variable in multiple MAT-files automatically. I assume you have multiple MAT-files created already. First of all, I recommend saving these files in a single directory.
Once done, kindly refer the below script.
matfiles = dir('<filepath>\*.mat'); %e.g. dir('C:\Users\*.mat')
x = zeros(512,512); %512-by-512 null matrix
N = length(matfiles) ;
for i = 1:N
save(matfiles(i).name, 'x', '-append')
end
This should append the variable 'x' to all the MAT-files in present your directory.
  1 件のコメント
KuanTing Wu
KuanTing Wu 2022 年 4 月 6 日
Hello, sorry for the late reply. I have solved this problem in another way a few days ago, but still appreciate your suggestion!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by