Typecasting higher dimension matrices
이전 댓글 표시
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
Florin Neacsu
2011년 9월 21일
Hello,
What do you mean?
A=[2,2;1,3];
B=single(A);
seems to work.
Regards,
Florin
Sean
2011년 9월 21일
채택된 답변
추가 답변 (1개)
Carl Witthoft
2020년 3월 30일
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
카테고리
도움말 센터 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!