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 Kommentare

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

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Rik
Rik am 27 Jan. 2018

0 Stimmen

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.

Kategorien

Gefragt:

am 27 Jan. 2018

Beantwortet:

Rik
am 27 Jan. 2018

Community Treasure Hunt

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

Start Hunting!

Translated by