Loop filenames into cell array that has numbers

Hi I am trying to create a cell array that has strings in the first column and numbers in the second but I keep getting a conversion error
mat = dir('*.mat');
nmat = length(mat);
new = cell(nmat,2);
for q = 1:nmat
matdata = load(mat(q).name);
if isfield(matdata,'DATA') && isfield(matdata.DATA, 'FastResp')
new(q,1) = {mat(q).name};
new(q,2) = matdata.DATA.FastResp.counter;
end
end

댓글 수: 2

Rik
Rik 2018년 1월 27일
Are you sure matdata.DATA.FastResp.counter contains a cell?
CompNsci
CompNsci 2018년 1월 27일
I think it's just storing a double

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

답변 (1개)

Rik
Rik 2018년 1월 27일

0 개 추천

mat = dir('*.mat');
nmat = length(mat);
new = cell(nmat,2);
for q = 1:nmat
matdata = load(mat(q).name);
if isfield(matdata,'DATA') && isfield(matdata.DATA, 'FastResp')
new{q,1} = mat(q).name;
if iscell(matdata.DATA.FastResp.counter)
new(q,2) = matdata.DATA.FastResp.counter;
else
new{q,2} = matdata.DATA.FastResp.counter;
end
end
end
Note that there might be a lot of empty cells if that check for fields fails.

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

질문:

2018년 1월 27일

답변:

Rik
2018년 1월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by