How to convert "64x128 single" into "64x128 double"?

1 回表示 (過去 30 日間)
Rachel Dawn
Rachel Dawn 2021 年 5 月 14 日
回答済み: KSSV 2021 年 5 月 14 日
I imported an array from python with this shape: (5, 25, 64, 128, 1) It's 5 sets of 25 images that are 64x128. I tried plotting one of these images on matlab to check if the data imported correctly and it did. this is the code i used to print the image (see below).
nely=64
nelx=128
latent_its(1,1,:,1)
x(1:nely,1:nelx)=latent_its(1,2,:,:)
imagesc(-x); colormap(gray);axis equal; axis tight; axis off;pause(1e-6)
But, for some reason the workspace says that x is a "64x128 SINGLE" vs. "64x128 DOUBLE" (not sure what this means but it should be double, otherwise when I input this x variable into a topology optimization code I needed it for, I get this error (below). When I use a 64x128 double generated in matlab, code works.
Error using +
Sparse single array arithmetic operations are not supported.
Error in comp_gen>FE (line 90)
K(edof,edof) = K(edof,edof) + x(ely,elx)^penal*KE;
Error in comp_gen (line 19)
[U]=FE(nelx,nely,x,penal);

回答 (1 件)

KSSV
KSSV 2021 年 5 月 14 日
You can convert a array A which single into double using:
A = double(A) ;
Read about single and double.

カテゴリ

Help Center および File ExchangeImages についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by