save a three dimensional matrix

15 ビュー (過去 30 日間)
Fariba
Fariba 2012 年 8 月 16 日
編集済み: Walter Roberson 2020 年 9 月 4 日
How can i save a three dimensional matrix. The following does not work
for b=1:size(GP,3);
Q(:,:,b)=wtpt*GP(:,:,b);
save('G:\.........\Q.txt','Q','-ASCII','-double');
end
Thanks

採用された回答

Titus Edelhofer
Titus Edelhofer 2012 年 8 月 16 日
Hi,
you have two options: one would be to save the individual slices
for b=1:size(GP, 3)
Q(:,:, b) = wtpt*GP(:,:,b);
A = Q(:,:,b);
save(sprintf('G:\Q_%d.txt', b), 'A', '-ASCII', '-double');
end
The alternative would be to use reshape to make it a 2D matrix, and when you load it, reshape it back to a 3D matrix. It depends what you need the ascii output for.
Titus
  4 件のコメント
Walter Roberson
Walter Roberson 2020 年 9 月 4 日
G: in this context is the drive letter that the original poster was using to save the file.
Walter Roberson
Walter Roberson 2020 年 9 月 4 日
編集済み: Walter Roberson 2020 年 9 月 4 日
None of the following support saving 3d matrices in 3d form:
  • save -ascii
  • dlmwrite
  • xlswrite
  • writetable, writematrix, writecell
  • imwrite for most image types
The following are some of the formats that support saving 3d matrices as 3d:
  • save (not -ascii)
  • Tiff class
  • dicomwrite
  • imwrite for a few image formats such as tiff
  • EDF file format support
  • HDF file format support
  • json

サインインしてコメントする。

その他の回答 (1 件)

luchen li
luchen li 2017 年 11 月 2 日
Hi, what does the wtpt* in
Q(:,:, b) = wtpt*GP(:,:,b) ; means?
  1 件のコメント
Walter Roberson
Walter Roberson 2017 年 11 月 2 日
That is something form the user's original code. We do not have any information on what the user was attempting to compute back then. It is not relevant to the matter of saving 3D arrays: it just illustrates how the user was constructing the 3D array.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeRead, Write, and Modify Image についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by