??? Subscripted assignment dimension mismatch.
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi can someone please help me with this error, below is my code
close all;
clear all;
dbstop if error
lambda2 = [2 4 6 8];
theta2 = [0*pi/180, 45*pi/180, 90*pi/180, 135*pi/180, 180*pi/180, 225*pi/180, 270*pi/180, 315*pi/180];
no_lamd = 4;
no_theta = 8;
psi = [0 pi/2];
gamma = 0.5;
bw = 1;
N = 1;
%%%%%%%%%%%%%%%%%%%%%%%%
ext = '.bmp';
dirr = 'H:\MATLAB\imgb\sign40\';
[tr_data] = textread('GPDS_40.txt','%s'); %train
[mtr ntr] = size(tr_data);%mtr
%assign class no
model = 40;
train = 5;
cnt = 0;
for i = 1:5:5*model
cnt = cnt + 1;
for j = 0:1:4
ts_class(i+j)=cnt;
end
end
save ts_class ts_class
%select train image
cnt1 = 0;
cnt2 = 0;
for j = 1:20:20*model
for i = 0:1:4
cnt1 = cnt1+1;
AR_train(cnt1) = tr_data(j+i);
end
cnt2 = cnt2+1;
AR_test(cnt2) = tr_data(j+5);
end size (AR_train');
size (AR_test');
%%%%%%%%%%%%%%%%%gabor train%%%%%%%%%%
c=0;
for x = 1:1:model*train
tr_im = AR_train(x);
tr_com = strcat(dirr,tr_im,ext);
tmp_tr =imread (char(tr_com));
col_size = 80*1.3;
row_size = 100*1.3;
im1 = im2double(tmp_tr);
F1 = imcrop (im1,[150 70 col_size-1 row_size-1]);
img_in = im2double(F1);
for m = 1:1:no_lamd
for n =1:1:no_theta
clear gb;
clear img_out;
clear img_out_disp;
lambda = lambda2(m)
theta = theta2(n)
c = c + 1;
gb_train = c
gb = gabor_fn(bw,gamma,psi(1),lambda,theta)...%gb is the n-th gabor filter
+1i * gabor_fn(bw,gamma,psi(2),lambda,theta);
img_out(:,:,n) = imfilter(img_in, gb, 'symmetric');
img_out_disp = sum(abs(img_out).^2,3).^0.5; %default superposition method, L2-norm
img_out_train(:,:,c) = (img_out_disp./max(img_out_disp(:)));%normalize (THIS IS THE ERROR)
end
end
end
3 comentarios
Jan
el 17 de Oct. de 2011
The code is hard to read. Please use the standard code formatting as described in the "Markup help" link.
For the "clear all" see: http://www.mathworks.com/matlabcentral/answers/16484-good-programming-practice#answer_22301 . Clearing the variables wastes time here without any benefits.
Respuestas (2)
Sean de Wolski
el 17 de Oct. de 2011
dbstop if error %enter this at the command line
Then run your program. It'll stop at the error, and look at the size of the RHS, and the size of the spot you're trying to stick it on the LHS. The size discrepancy will hopefully be obvious.
0 comentarios
Fangjun Jiang
el 17 de Oct. de 2011
I am copying my answer to another question here.
The error is due to, well, "Subscripted assignment dimension mismatch".
Try this example to see it:
a=zeros(3,4);
a(:,1)=rand(5);
Put a break point at the line where the error happened, then check the size of the right hand variable and left hand variable. For example, in the above example:
>> size(rand(4))
ans =
4 4
>> size(a(:,1))
ans =
3 1
They apparently don't match.
0 comentarios
Ver también
Categorías
Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!