How to resolve the error "cell contents reference from a non-cell array object"? Thank you!!
Show older comments
Looking for help on my project. Any help is largely appraciated!!
fid = fopen('test.cal');
[paramlist l] = textscan(fid, '%s %s %s %s %s');
fclose(fid);
[len wid] = size(paramlist{1}); %[len wid]=[18 1]
j = 1;
chanlist = cell(1,len); %create a cell array named chanlist
for i=1:len
if(strcmp(paramlist{1}{i},'channel'));
chanlist{1,j} = {paramlist{2}{i},paramlist{3}{i},paramlist{4}{i},paramlist{5}{i}};
disp(chanlist{1,j});
j=j+1;
end
end
for i=1:len
if(strcmp(chanlist{i}{1}, 'DIGOUT'))%%when I run the code, it shows error happens here
if (str2double(chanlist{i}{3}) < 28) %28 digital IOs on a minilab1008
if (strcmp(chanlist{i}{2}, '0'))
disp('board 0 DIGOUT');
elseif (strcmp(chanlist{i}{2},'1'))
disp('board 1 DIGOUT');
else 'only boards 0 and 1 supported';
end
else 'ignoring digital output';
end
elseif strcmp(chanlist{i}{1}, 'DIGIN')
if (str2double(chanlist{i}{3}) < 28) %28 digital IOs on a minilab1008
if (strcmp(chanlist{i}{2}, '0'))
disp('board 0 DIGIN');
elseif (strcmp(chanlist{i}{2},'1'))
disp('board 1 DIGIN');
else 'only boards 0 and 1 supported';
end;
else 'ignoring digital output';
end;
end
end
Here is the "test.cal" file: (3rd column represents board number, 4th column represents line/channel number)
channel DIGOUT 0 0 shutter1
channel DIGOUT 0 1 shutter2
channel DIGOUT 0 2 shutter3
channel DIGOUT 0 3 shutter4
channel DIGOUT 1 0 shutter5
channel DIGIN 0 4 shutter1state
channel DIGIN 0 5 shutter2state
channel DIGIN 0 6 shutter3state
channel DIGIN 0 7 shutter4state
channel DIGIN 1 1 shutter5state
channel ANAOUT 0 0 TempCtrlVolt
channel ANAOUT 0 1 PositionCtrlVolt
channel ANAOUT 1 0 TempCtrlVolt
channel ANAIN 0 0 PSUVolt
channel ANAIN 0 1 PositionCtrlState
channel ANAIN 1 0 PSUVolt
calib TempCtrlVolt 0 120
calib TempCtrlVolt 1 120
Accepted Answer
More Answers (1)
Fangjun Jiang
on 7 Dec 2011
You have 18 lines in the text file. The variable "paramlist" got the correct value after reading the file. The variable "chanlist" is set as 1x18 cells. The value of "len" is 18 which is also correct.
However, in your first for-loop, because you have the comparison to check for the string of 'channel', only the first 16 cells of "chanlist" are assigned correct value. The 17th and 18th cells are empty. That is why it causes error when you do the second for-loop with 18 iterations.
If you change the second for-loop as below, it will run without error. However, I am not sure if that is what you want.
for i=1:j-1 %len
Jan's recommendation of using "dbstop if error" is really a good suggestion. You can also try to run the code step by step. But because the error happened at the later part of the for-loop. "dbstop if error" is truly the best to pin-point the error.
Categories
Find more on Cell Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!