Typecasting higher dimension matrices
Mostrar comentarios más antiguos
I recently found (to my chagrin) that the typecast function only works on scalars and 1D matrices (i.e. arrays).
Does anyone know of a way to typecast matrices with 2, 3, 4, or more dimensions (other than simply indexing out and typecasting all the elements or 1st dimension arrays into a new variable?
2 comentarios
Florin Neacsu
el 21 de Sept. de 2011
Hello,
What do you mean?
A=[2,2;1,3];
B=single(A);
seems to work.
Regards,
Florin
Sean
el 21 de Sept. de 2011
Respuesta aceptada
Más respuestas (1)
Carl Witthoft
el 30 de Mzo. de 2020
If you know a little bit about your 2D array in advance, then try this - seemed to work for me
Here I know my columns are 4*N bytes long, and that I want to typecast column-wise
arrsize = size(arrdat);
f32 = zeros(arrsize(1)/4, arrsize(2) );
for jrow = 1:4:size(arrdat,1),
count4 = jrow:jrow+3;
rowquad = arrdat(count4,:);
f32((1+(jrow-1)/4),:) = double(typecast(rowquad(:), 'single'));
end
Categorías
Más información sobre Data Type Conversion en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!