MATLAB Answers

Hi,there is error showing that the variable is varying.Someone help me plz

1 view (last 30 days)
Dhanya Francis
Dhanya Francis on 23 Jan 2016
Answered: Walter Roberson on 23 Jan 2016
for i=1:M
str=strcat('C:\Users\Dhanya Francis\Desktop\Project\',int2str(i),'.jpg');
eval('img=imread(str)');
subplot(ceil(sqrt(M)),ceil(sqrt(M)),i)
imshow(img)
if i==2
title('Training set','fontsize',18)
end
drawnow;
[irow,icol]=size(img);
img(irow,icol) ;
temp=reshape(img,irow*icol,1);
S=horzcat(S,temp);
  1 Comment
Image Analyst
Image Analyst on 23 Jan 2016
S and temp don't have the same number of rows. In fact, S was never even defined before you tried to use it, or at least if it was, you didn't show that code.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 23 Jan 2016
Do not use eval!
str = fullfile('C:\Users\Dhanya Francis\Desktop\Project\', sprintf('%d.jpg', i));
img = imread(str);
Your line
[irow,icol]=size(img);
is incorrect for any RGB image, and .jpg are almost always RGB images.
[d1,d2,d3,...,dn] = size(X), for n > 1, returns the sizes of the dimensions of the array X in the variables d1,d2,d3,...,dn, provided the number of output arguments n equals ndims(X). If n does not equal ndims(X), the following exceptions hold:
n < ndims(X) di equals the size of the ith dimension of X for 0<i<n, but dn equals the product of the sizes of the remaining dimensions of X, that is, dimensions n through ndims(X).

Community Treasure Hunt

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

Start Hunting!

Translated by