1
votes

when I run the code below, I got the following error :

Cell contents reference from a non-cell array object.

folder can take 1 or several folders

for x=1:numel(folder)
    y{x} = fullfile(folder{x},'Status.xml');
    getFile = fileread(char(y{x}));
    content{x} = strtok(getFile ,';');
end


>>whos folder
  Name        Size            Bytes  Class     Attributes

  folder      1x1               941  struct         


>> numel(folder)
ans= 
1
1
Maybe initialise y before the loop as y={}? - Dan
it seems like folder is not defined when you run your code - Shai
type >> which folder and >> class(folder) and see what the output you get. - Shai
@Shai: I believe folder is defined. Or else, the error message would be for numel(folder) and not folder{x}. Or am I wrong? (It might of course be defined as something else than a cell array.) - Stewie Griffin
What do you get if you simply type folder? What are the entries in folder? folder.a, folder.b? If you have several folders, would that be: folder(1).a, folder(2).a etc? - Stewie Griffin

1 Answers

0
votes

Assuming folder is a cell array, I believe this should work:

y = cell(numel(folder), 1);

for x=1:numel(folder)
    y{x} = fullfile(folder{x},'Status');
    getFile = fileread(char(y{x}));
    content{x} = strtok(getFile ,';');
end

Your error is most likely with y{ii}. I guess y is not pre-defined.

Also: you use ii as index in y, whereas you use x in the loop.

In case folder is a normal matrix, have you tried using just folder(x)?

UPDATE:

I see from your updated question that folder is a struct, not a cell. Try the following, where you substitute .field with whatever you name your entries in folder.

y = cell(numel(folder), 1);
content = cell(numel(folder), 1);

for x=1:numel(folder)
    y{x} = fullfile(folder(x).field,'Status');
    getFile = fileread(char(y{x}));
    content{x} = strtok(getFile ,';');
end