Error using ' . Transpose on ND array is not defined. Use PERMUTE instead.
Show older comments
I got an error in my Matlab, the following is the code:
Tdb = [];
for i = 1 : Train_Number
str = int2str(i);
str = strcat('\',str,'.jpg');
str = strcat(TrainPath,str);
img = imread(str);
[row col] = size(img);
tmp = reshape(img',row*col,1); <-- My Error is Here!!! % Reshaping 2D images into 1D image vectors
Tdb = [Tdb tmp]; % 'T' grows after each turn
end
Train_Number = size(Tdb,2);
Error using ' Transpose on ND array is not defined. Use PERMUTE instead.
Error in FRecog>pushbutton3_Callback (line 161) tmp = reshape(img',row*col,1); % Reshaping 2D images into 1D image vectors
When I use 'PERMUTE', the error is "Too many input arguments"
Please kindly check my error! Thank you.
Answers (2)
Geoff Hayes
on 7 Mar 2016
Almal - please verify that your image is in fact a 2D image. If it is 3D, then you cannot transpose it. For example, the following lines of code generates the same error
img = randi(255,50,50,3);
img'
You forgot that images are 3D arrays, not 2D matrices. Try this:
img = imread(str);
size(img)
and you will find that img is actually an RxCx3 array, not a simple 2D matrix. This also means that your code:
[row col] = size(img);
is wrong. Read the size documentation and you will learn that the last output is the product of all trailing dimensions, so actually the last output would thus be the number of rows * 3.
You need to rethink your algorithm, because you did not take into account the fact the images are 3D arrays of data.
1 Comment
Zoe Liu
on 20 Apr 2016
Thx a lot~
Categories
Find more on Matrices and 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!