What is the error, attempt to grow an array along ambiguous dimension?

조회 수: 4 (최근 30일)
Billy
Billy 2012년 12월 3일
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
Billy
Billy 2012년 12월 3일
The error apparently involves line of canv3(filter)=canv2(filter); and I tried changing that line of code and the error still came up. I'll try checking the size.
Jan
Jan 2012년 12월 3일
@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).

댓글을 달려면 로그인하십시오.

답변 (3개)

Jan
Jan 2012년 12월 3일
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].
  1. Avoid using the name "filter" for variables, because it is a built-in function
  2. 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
Billy
Billy 2012년 12월 4일
편집: Billy 2012년 12월 4일
I get the error where canv3(index)=canv2(index).
Attempt to grow array along ambiguous dimension.
Error in imageTestTranslate (line 54)
canv3(index) = canv2(index);
Matt J
Matt J 2012년 12월 4일
편집: Matt J 2012년 12월 4일
You cannot use linear indexing or other kinds of 1-dimensional indexing to grow an array that is not a vector.

댓글을 달려면 로그인하십시오.


Matt J
Matt J 2012년 12월 3일
편집: Matt J 2012년 12월 3일
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).
  댓글 수: 1
Billy
Billy 2012년 12월 4일
Yes, that appears to be true. How could I make the number of elements the same?
numel(filter)
ans =
3959856
numel(canv3)
ans =
3932160

댓글을 달려면 로그인하십시오.


Matt J
Matt J 2012년 12월 4일
편집: Matt J 2012년 12월 4일
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{:});

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by