Integers can only be combined with integers of the same class, or scalar doubles

조회 수: 59 (최근 30일)
Neo
Neo 2015년 12월 22일
편집: DGM 2024년 8월 26일
Error using - Integers can only be combined with integers of the same class, or scalar doubles.
Error in Code (line 27) data = data - repmat(mn,1,N);
Here is the code snip, where I am subtracting off the mean of some matrices:
mn = mean(data,2);
data = data - repmat(mn,1,N);
I tried casting the new data matrix to an int16 but that gave the same error, not sure what to cast it to, to avoid error.
  댓글 수: 3
jgg
jgg 2015년 12월 22일
편집: jgg 2015년 12월 22일
I added my answer below.
Are the matrices square? If they're not square, the * operator is matrix multiplication, if they're like NxM this is asking Matlab to do NxM * NxM which doesn't work. If you want to multiply them component-wise, the operator is .*.
See here for example.
jgg
jgg 2015년 12월 22일
I think you should post another question to cover this, and give more background. I don't really understand what you're trying to do here, so you might want to explain very precisely what you're trying to accomplish, and what the objects you're working with are. (For instance, why are you trying to get the eigenvalues of a non-square matrix? Which operation made it non-square; it wasn't subtracting off the means.)

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

채택된 답변

jgg
jgg 2015년 12월 22일
편집: jgg 2015년 12월 22일
Try setting data = double(data) first.
  댓글 수: 2
Neo
Neo 2015년 12월 22일
Oh wait, why did the matrix have to be casted into a double, I know because we didn't want the error, but why have an error in the first place?

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

추가 답변 (2개)

sai kumar
sai kumar 2017년 10월 24일
편집: sai kumar 2017년 10월 24일
i have the same problem please help me!!.
Error using mod
Integers can only be combined with integers of the same class, or scalar doubles.
Error in trial>decryption_Callback (line 457) m1(l)=mod(c2,n); code: c1=reshape(c,1,[]); s=numel(c1); m1=c1; c2=c1; for l=1:s c2(l)=c1(l)^msk; m1(l)=mod(c2,n); end

lokesh kumar
lokesh kumar 2020년 6월 24일
편집: DGM 2024년 8월 26일
Error???????????????????????
%rough dark channel computation%
%a=imread('D:\Image processing project\image\hazy.jpg');
a=imread('D:\Image processing project\contrast\dark channel prior\dehaze_code\dehaze_code\inputImgs\forest_input.png');
[ht,wt,~]=size(a);
patchSize=15;
padSize=7;
JDark=zeros(ht,wt);
imj=padarray(a,[padSize padSize],inf);
for i=1:ht
for j=1:wt
patch=imj(i:(i+padSize-1),j:(j+padSize-1),:);
JDark(i,j)=min(patch(:));
end
end
atmSum=zeros(1,3);
imsize=ht*wt;
numpx=floor(imsize/1000);
JDarkVec=reshape(JDark,imsize,1);
ImVec=reshape(a,imsize,3);
[JDarkVec,indices]=sort(JDarkVec);
indices=indices(imsize-numpx:end);
atmSum=zeros(1,3);
for ind=1:numpx
atmSum=atmSum+ImVec(indices(ind),:);
end
A=atmSum/numpx;
figure;
imshow(uint8(A));
So what is the problem with the atmSum, it is not working. Anybody wants to solve this problem are always welcome.
or email me: lokesh.singh.in@gmail.com
Thanks
  댓글 수: 1
DGM
DGM 2024년 8월 26일
Since the intermediate sum will exceed the dynamic range of the original integer class, do the accumulation in float. This avoids mixed class arithmetic problems, and it avoids truncation.
ImVec = double(ImVec);

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by