What is the error, attempt to grow an array along ambiguous dimension?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hello, what is the error attempt to grow an array along ambiguous dimension? And, how would I be able to fix that. The code that gives the error is.
for j = 1:rep
canv2 = canv;
del = j*inc;
canv2(1+del:row+del,1+del:col+del,:) = cm;
filter = find(canv2 > 0);
canv3 = bg;
canv3(filter) = canv2(filter);
image(canv3)
pause(0.05)
end
3 comentarios
Jan
el 3 de Dic. de 2012
@Billy: Please do not only mention, that you have changed the code, but show us the new code also. We do not have crystal balls (except for Walter, of course).
Respuestas (3)
Jan
el 3 de Dic. de 2012
When canv3 is an array with more than 1 non-singelton dimension (e.g. 2D matrix or 3D), using a linear or logical index for growing cannot be interpreted uniquely anymore:
x = [1,2; 3,4];
x([true, true, true, true, true, true]) = 7;
Does this create the same error message? If so, Matlab cannot decide, if the new array should be [2x3] or [3x2].
- Avoid using the name "filter" for variables, because it is a built-in function
- Let canv3 grow explictly at first:
index = (canv2 > 0); % not "filter"
s = size(canv2);
if any(size(canv3) < s)
canv3(s(1), s(2), s(3)) = 0; % Grow
end
canv3(index) = canv2(index);
4 comentarios
Matt J
el 4 de Dic. de 2012
Editada: Matt J
el 4 de Dic. de 2012
You cannot use linear indexing or other kinds of 1-dimensional indexing to grow an array that is not a vector.
Matt J
el 3 de Dic. de 2012
Editada: Matt J
el 3 de Dic. de 2012
Copy/paste the error messages, so we can see what lines generate them and also the output of WHOS so we can see the sizes of all your variables.
My guess would be that it occurs in this line
canv3(filter) = canv2(filter);
and that it occurs because "filter" contains indices greater than numel(canv3).
Matt J
el 4 de Dic. de 2012
Editada: Matt J
el 4 de Dic. de 2012
If the whole point of all this is to translate an image by an integer amount, just use circshift
canv3=circshift(canv2,shiftvector) + bg;
or the function below if you want non-circulant shifting.
function [B,src_indices,dest_indices]=noncircshift(A,offsets)
%Like circshift, but shifts are not circulant. Missing data are filled with
%zeros.
%
% [B,src_indices,dest_indices]=noncirchift(A,offsets)
%
%B is the resulting array and the other outputs are such that
%
% B(dest_indices{:})=A(src_indices{:})
siz=size(A);
N=length(siz);
if length(offsets)<N
offsets(N)=0;
end
B=zeros(siz);
indices=cell(3,N);
for ii=1:N
for ss=[1,3]
idx=(1:siz(ii))+(ss-2)*offsets(ii);
idx(idx<1)=[];
idx(idx>siz(ii))=[];
indices{ss,ii}=idx;
end
end
src_indices=indices(1,:);
dest_indices=indices(3,:);
B(dest_indices{:})=A(src_indices{:});
0 comentarios
Ver también
Categorías
Más información sobre Matrix Indexing 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!