필터 지우기
필터 지우기

Error using reshape To RESHAPE the number of elements must not change.

조회 수: 3 (최근 30일)
pallavi singh
pallavi singh 2021년 6월 16일
댓글: Walter Roberson 2021년 6월 19일
can anyone tell me where is the error?
yw=Eband;
k=NoOfBands;
xrtemp=reshape(Eband(k),1,S(1,1)*S(1,2));
k=k-1;
for i=2:size(S,1)-1
xrtemp=[xrtemp reshape(Eband(k-1),1,S(i,1)*S(i,2)) reshape(Eband{k},1,S(i,1)*S(i,2)) reshape(Eband{k-2},1,S(i,1)*S(i,2))];
k=k-3;
end
DImg=(waverec2(xrtemp,S,wname));
nl_mnt=im_nl+DImg;
nl_mnt8=uint8(nl_mnt);
toc

답변 (1개)

Walter Roberson
Walter Roberson 2021년 6월 16일
편집: Walter Roberson 2021년 6월 16일
k=NoOfBands;
That has the appearance of being a scalar.
xrtemp=reshape(Eband(k),1,S(1,1)*S(1,2));
We do not know what Eband is. If it is numeric or cell, then if k is a scalar then Eband(k) would be a scalar. You would then be attempting to reshape a scalar to be 1 by something, but that something does not look likely to happen to exactly equal 1.
If Eband is a function, then the previous like
yw=Eband;
would have been an invocation of the function without passing in any parameters. It could work and still have Eband(k) work, but it is not obvious that it will.
If Eband is the handle to a function, then the assignment to yw would be assigning a copy of the handle, and Eband(k) would be invoking the function. We cannot rule it out.
But let us look at
xrtemp=[xrtemp reshape(Eband(k-1),1,S(i,1)*S(i,2)) reshape(Eband{k},1,S(i,1)*S(i,2)) reshape(Eband{k-2},1,S(i,1)*S(i,2))];
and notice that Eband{k} and Eband{k-2} are referenced. Those are cell array references. We can then guess that the code you wanted was
xrtemp=reshape(Eband{k},1,S(1,1)*S(1,2));
If so that could also be written as
xrtemp = Eband{k}(:).';
  댓글 수: 6
pallavi singh
pallavi singh 2021년 6월 19일
xrtemp =
Columns 1 through 10
-10.5347 24.4846 5.8826 -6.6274 40.2777 49.4878 -38.7338 -35.6576 -14.1041 37.4271
Columns 11 through 13
51.4417 -21.5861 20.4357
S =
32 32
32 32
64 64
128 128
256 256
512 512
Walter Roberson
Walter Roberson 2021년 6월 19일
nl = S(1,1) = 32, nc = S(1,2) = 32, and there are not at least 3 columns in the S matrix.
In this configuration, the code expects to be reconstructing a 32 x 32 signal, and so needs xrtemp to have at least 32*32 = 1024 entries. But xrtemp only has 13 entries.
The way you build xrtemp is not compatible with the S matrix you have.

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

카테고리

Help CenterFile Exchange에서 Graphics Object Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by