フィルターのクリア

Vectroizing lots of MAT FILEs

2 ビュー (過去 30 日間)
Karthik Nagaraj
Karthik Nagaraj 2020 年 10 月 16 日
コメント済み: Karthik Nagaraj 2020 年 11 月 10 日
Have 100 .mat files of size NXN.
The mat files have data that are similar to toepleitz matrix and the values are complex double in nature.
My requriement is to save 3 different types of vectors for each matfile
1. Convert the contents of NxN matfile into N2X1 vector.
2. Extract the diagonal elements from the mat file and save into another row vector
3. Extract the first row of the mat file and store into another vector.
Please guide.

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 10 月 17 日
You can do something like the following code. It assumes that each .mat file have a matrix named 'M'
files = dir('*.mat');
for i = 1:numel(files)
filename = files(i).name;
data = load(filename);
M = data.M;
v1 = M(:); % 1. Convert the contents of NxN matfile into N2X1 vector.
v2 = diag(M); % 2. Extract the diagonal elements from the mat file and save into another row vector
v3 = M(1,:); % 3. Extract the first row of the mat file and store into another vector.
save(filename, 'M', 'v1', 'v2', 'v3')
end
  3 件のコメント
Walter Roberson
Walter Roberson 2020 年 10 月 18 日
Replace data.M with data. followed by the name of the variable stored in the file.
Karthik Nagaraj
Karthik Nagaraj 2020 年 11 月 10 日
Thank you Mr Roberson thank you further explanation

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeWorkspace Variables and MAT-Files についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by