Vectroizing lots of MAT FILEs

조회 수: 1 (최근 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 CenterFile Exchange에서 Workspace 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