Subscripted assignment dimension mismatch error
Ältere Kommentare anzeigen
am working on an image processing project and i am getting an error on line 35. the error is Subscripted assignment dimension mismatch error. i have tried to fix it in vain. could someone help me please
- %D0=25x25 image(double)
- %Y=25x5000 signal(double)
- [m,n0] = size(D0);
- [~,N] = size(Y);
- itcmat = zeros(iters/iter_check, n0-nmin+1);
- D0run = D0;
- ii = 1;
- vn = [n0]; % vector of actual sizes
- for it = 1 : iter_check : iters
- % run the algorithm for a few iterations
- [D, X, ~] = DL(Y, D0run, s, iter_check, str2func(update), params, 'replatom', replatom);
- % order dictionary based on representation power
- [~, atom_list] = sort(sum(X.*X,2), 'descend');
- % compute ITC for all dictionary sizes (with ordered atoms)
- n1 = max(nmin, vn(ii) - ncand);
- for n2 = n1 : vn(ii)
- Dn = D(:, atom_list(1:n2));
- Xn = omp(Y, Dn, s);
- rmse = norm(Y-Dn*Xn, 'fro')/sqrt(m*N);
- if itc_index > 10
- itc2 = com_itc_BS_2( Y, Dn, Xn, rmse );
- itcmat(ii,n2-n1+1) = itc2(itc_index-10);
- else
- [~, itc2] = com_itc_BS( Y, Dn, Xn, rmse );
- itcmat(ii,n2-n1+1) = itc2(itc_index);
- end
- end
- % trim or enlarge dictionary
- [~,n2] = min(itcmat(ii,1:vn(ii)-n1+1)); % compute min value of ITC
- n2 = n2 + n1 - 1;
- nopt(ii) = n2; %% error Subscripted assignment dimension mismatch.
- itcmat(ii,vn(ii)-n1+2:n0-n1+1) = itcmat(ii,vn(ii)-n1+1); % fill with last value of ITC
- if n2 < vn(ii) - nminus % dictionary is too big
- n2 = max(nmin, vn(ii) - nminus);
- D0run = D(:, atom_list(1:n2)); % continue with new dictionary
- elseif n2 < vn(ii)-1
- n2 = max(nmin, vn(ii) - 1);
- D0run = D(:, atom_list(1:n2)); % continue with new dictionary
- elseif n2 == vn(ii) % dictionay may be too small, increase size
- %n = vn(ii);
- n2 = vn(ii) + nplus;
- Dplus = randn(m,nplus);
- Dplus = normc(Dplus);
- D0run = [D Dplus]; % continue with new dictionary
- end
- vn(ii+1) = n2;
- % final operations
- X = omp(Y, D0run, s); % compute RMSE just to see it
- rmse = norm(Y-D0run*X, 'fro')/sqrt(m*N);
- rmsev(ii) = rmse;
- ii = ii+1;
- end
- % final refinement: a few DL iterations with the final size
- if nopt(ii-1) < vn(ii-1)
- D0run = D(:, atom_list(1:nopt(ii-1))); % cut dictionary to optimal number of atoms
- end
- [D, ~, ~] = DL(Y, D0run, s, iter_check, str2func(update), params, 'replatom', replatom);
- X = omp(Y, D, s);
- rmse = norm(Y-D*X, 'fro')/sqrt(m*N);
- % final operations
- X = omp(Y, D0run, s); % compute RMSE just to see it
- rmse = norm(Y-D0run*X, 'fro')/sqrt(m*N);
- rmsev(ii) = rmse;
- ii = ii+1;
- end
- % final refinement: a few DL iterations with the final size
- if nopt(ii-1) < vn(ii-1)
- D0run = D(:, atom_list(1:nopt(ii-1))); % cut dictionary to optimal number of atoms
- end
- [D, ~, ~] = DL(Y, D0run, s, iter_check, str2func(update), params, 'replatom', replatom);
- X = omp(Y, D, s);
- rmse = norm(Y-D*X, 'fro')/sqrt(m*N);
2 Kommentare
You should be able to determine what the problem is in 10s using the debugger and the 'Pause on errors' option. It is a lot more difficult to just scan 85 lines of code and try to work out what is happening.
nopt is not predeclared, which may be the cause, but equally if n2 is non-scalar on any iteration of the loop then this would give this error, as it would also if n2 is empty ( [] ).
In my opinion, it would be much easier to read the code if it had been formatted as code (with no line numbers) using the
button.
button.The error is because ii and n2 are not the same size. As Adam says, the debugger is the best way to find out what size they are.
We have
[~,n2] = min(itcmat(ii,1:vn(ii)-n1+1)); % compute min value of ITC
n2 = n2 + n1 - 1;
nopt(ii) = n2; %% error Subscripted assignment dimension mismatch.
So, n2 (at least this n2 since n2 is used for many purposes including the loop index. An infinity of variable names available, yet n2 has to be reused many times!) is the index of the minimum of a row of a matrix. So it must be scalar.
Most likely n1 is not scalar. n1 is the max of two things which do not appear anywhere else in the code, so we don't know what their size is. Most likely, nmin or ncand is not scalar.
Antworten (0)
Kategorien
Mehr zu Functions for Programming and Data Types finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!