how to read multiple mat files and and extract data from those

조회 수: 27 (최근 30일)
OriAlpha
OriAlpha 2018년 10월 7일
댓글: Madusha Sammani 2021년 9월 21일
I have a multiple .mat files (like 100 file) I need to load and extract specific data from those files. I.e to extract the row and columns so can anyone please help me out in this.
  댓글 수: 2
Kevin Chng
Kevin Chng 2018년 10월 7일
mat = dir('*.mat');
for q = 1:length(mat)
load(mat(q).name);
end
However, you are mentioning you want to extract specific data from those files. As per my knowledge, may be we need to know what is the name of variable in the mat file first.
May be you can attach few of your mat file, and further elaborate it. So may be some of expert here can try it out.
OriAlpha
OriAlpha 2018년 10월 7일
hello, has I mentioned above I have these type .mat files (like 150 files). i have to load all those files and have to extract column 11 in this all mat files and save it in one .mat file
i have attached few files below

댓글을 달려면 로그인하십시오.

채택된 답변

Kevin Chng
Kevin Chng 2018년 10월 7일
Hi Suhas Goravale Siddaramu,
I have tried out your attached mat. file. I guess you are saying row 11 instead of column 11. In your mat.file, there is variable Pre-cell, it has 3 columns and 14 rows.
mat = dir('*.mat');
for q = 1:length(mat)
load(mat(q).name);
data(q,:) = Pre_cell(11,:)
end
with the additional line of code data(q,:) = Pre_cell(11,:), it will load all the row 11 of mat file into data.
Should you have any doubt, you may ask.
  댓글 수: 4
OriAlpha
OriAlpha 2018년 10월 8일
Hello, I have another doubt
I have made a loop which loads all mat files in a folder then I have applied multiple functions for all the mat files and even the operation is going without errors and the last thing is that I have to save one loop value to one file.
like for 1 loop it should create 1 file
for example if 200 loops it should create with 200 files with different names.
so how can i do it

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

ANKUR KUMAR
ANKUR KUMAR 2018년 10월 7일
Whenever you wish to load all files, just use dir.
F=dir('*.mat')
for i =1:length(F)
load(F(i).name)
end

카테고리

Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by