Errors in manipulating a matrix of images

7 views (last 30 days)
Hi,
I have a one dimensional matrix made up of 10 50x50 binary images
I need to go through each image and perform some image manipulation on it.
But when I get to the first 1 and try to use it, I get the error:
Cell contents reference from a non-cell array object.
Error in cell2mat (line 42)
cellclass = class(c{1});
Error in andrewmetcalfImage (line 8
X =cell2mat(Tmatrix{x});
The simplified code that generates this error is:
N = 10;
Tmatrix = cell(1,N);
T_File = 'training_set/t%d.bmp';
for i=1:N
Tmatrix{i} = imcomplement(im2bw(imread(sprintf(T_File, i))));
end
X =cell2mat(Tmatrix{1});
Ultimately, I need to take each image and do some image manipulation, the results of which I would like to store in a different matrix.

Accepted Answer

Image Analyst
Image Analyst on 27 Jul 2014
Edited: Image Analyst on 27 Jul 2014
Tmatrix is a cell array. So Tmatrix(1) is a cell. And Tmaxtrix{1} is a logical array. Since Tmatrix{1} is not a cell, you can't pass it in to cell2mat(), which expects a cell or cell array. To fix, use one of these lines of code:
X = cell2mat(Tmatrix(1)); % Uses parentheses
or
X = Tmatrix{1}; % Uses braces
X will be a logical matrix if you use either of those. Next, please read the FAQ to get a better intuitive feeling for what a cell array is and how to reference it: http://matlab.wikia.com/wiki/FAQ#What_is_a_cell_array.3F It will also show you when to use parentheses and when to use braces (which was the cause of your problem).

More Answers (0)

Categories

Find more on Data Type Conversion 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!