Read multiple .mat files in the file path in sequence

조회 수: 11(최근 30일)
mehmet irfan gedik
mehmet irfan gedik 2019년 8월 30일
댓글: mehmet irfan gedik 2019년 8월 30일
Hi everyone,
There are 10 .mat files in the file path. I need to read the value of one matrix (called 'Scanning') in this file and keep it in another.
For instance ,
0_cm(1).mat , 0_cm(2).mat .... 0_cm(10).mat
I get the error when I write the following matlab code and filename is a string type, so I can't access files with the variable i.
Test = [];
for i=1:10
filename = "D:\matlab\0_cm(i).mat";
myVars = {'Scanning'};
S = load(filename,myVars{:});
Test = S.Scanning(:,64)
end
Thanks for your answer in advance.

답변(2개)

dpb
dpb 2019년 8월 30일
for i=1:10
filename = sprintf('D:\matlab\0_cm(%d).mat',i); % build specific file name
myVars = {'Scanning'};
S = load(filename,myVars{:});
Test = S.Scanning(:,64)
end
  댓글 수: 3
mehmet irfan gedik
mehmet irfan gedik 2019년 8월 30일
@dpb, yes an error is emerging as @Stephen Cobeldick mentions.
Warning: Escaped character '\m' is not valid. See 'doc sprintf' for supported special characters.
Thanks @Stephen Cobeldick,

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


mehmet irfan gedik
mehmet irfan gedik 2019년 8월 30일
편집: mehmet irfan gedik 2019년 8월 30일
Thanks @Steven Lord ,
We could actually solve the problem with a fairly simple method.
Edit : But I wonder why the sprintf function is causing such a problem ???.
  댓글 수: 2
mehmet irfan gedik
mehmet irfan gedik 2019년 8월 30일
@David K. , Thank you for your descriptive sentences.

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

Community Treasure Hunt

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

Start Hunting!

Translated by