Error Integers can only be combined with integers of the same class, or scalar doubles when processing my sample?
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have a3, it's data < 64x490 int16 > , and i wanted to do *row1*row1*1 then row2*row2*2 to row49*row49*49 and have the sum of it. And apply it to all other columns too. i have tried using this code :
[g,h]=size(a3);
m=1:g;
t=sum(a3(m,:).*a3(m,:).*m);
but i get this error message : ??? Error using ==> times Integers can only be combined with integers of the same class, or scalar doubles.
this code work only if we remove the .*m and become like this:
[g,h]=size(a3);
m=1:g;
t=sum(a3(m,:).*a3(m,:));
but the formula from row1*row1*1 become row1*row1 only, can anyone correct my mistake ?
0 comentarios
Respuestas (2)
Image Analyst
el 11 de Mzo. de 2013
Try
m = int16(1:g);
Be aware that if the numbers get larger than 32767, they will clip.
0 comentarios
Wayne King
el 11 de Mzo. de 2013
The error you get is because
m = 1:g;
gives you a double precision vector, while a3 is int16. You can remove that error by casting m to int16
m = int16(1:g);
or a3 to double precision
a3 = double(a3);
but then you're going to get dimension error. Did you mean to have a for loop?
1 comentario
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!