Error using reshape To RESHAPE the number of elements must not change.
2 次查看(过去 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
0 个评论
回答(1 个)
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 个评论
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 Center 和 File Exchange 中查找有关 Graphics Object Programming 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!