필터 지우기
필터 지우기

Sir i have 200.mat file in one folder and i want program that read it automatically without merging the files

조회 수: 1 (최근 30일)
I have folder name 1 which contain 1B.mat file to 193B.mat file. I want to read directly this files with merging in single .mat file or using direclty call by for loop
clear
PathName = uigetdir;
file_all = dir(fullfile(PathName,'C:\User:\DELL:\Desktop:\F1folder:\1'));
matfile = file_all([file_all.isdir] == 0);
clear file_all PathName
%d=dir('*.mat'); % get the list of files
x=[]; % start w/ an empty array
for i=1:length(matfile)
x=[x;load(matfile(i).name)]; % read/concatenate into x
end
b=[];
for j=1:length(x)
b=[b; x(j, 1).variable1];
end
FileName = [matfile(i,1).name(1:end-9),'.mat'];
save(FileName,'matfile','x','b');
showing error
Index in position 2 exceeds array bounds.
Error in Untitled2 (line 15)
FileName = [matfile(i,1).name(1:end-9),'.mat'];

답변 (2개)

Jan
Jan 2019년 1월 7일
편집: Jan 2019년 1월 7일
file_all = dir(fullfile(PathName,'C:\User:\DELL:\Desktop:\F1folder:\1'));
This is strange: User names and other folder names cannot contain colons. I guess you mean:
file_all = dir(fullfile(PathName,'C:\User\DELL\Desktop\F1folder\1'));
Clearing variables is rarely useful in Matlab. Omit this to simplify your code:
clear file_all PathName
You can replace
b=[];
for j=1:length(x)
b=[b; x(j, 1).variable1];
end
by:
b = [x.variable1];
This is nicer and faster.
  댓글 수: 3
jaypal singh
jaypal singh 2019년 1월 7일
Simply i have one folder it's name is '1' and it contains 1B-193B.mat files . I want to call directly this files 193B.mat files
Jan
Jan 2019년 1월 7일
"getting errore" is not clear. Please post your code and the complete error message.
What does "I want to call directly this files 193B.mat files" mean?

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


KSSV
KSSV 2019년 1월 7일
FileName = [matfile(i,1).name,'.mat'];
The above line is enough....
  댓글 수: 1
jaypal singh
jaypal singh 2019년 1월 7일
Simply i have one folder it's name is '1' and it contains 1B-193B.mat files . I want to call directly this files 193B.mat files

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

카테고리

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

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by