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

5 次查看(过去 30 天)
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 中查找有关 Shifting and Sorting Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by