保存和加载3D矩阵的方法

问题描述

我需要在文本文件中保存3D矩阵,然后将其加载到Matlab中(我不掌握)。我的第一个想法是使用这样的.csv文件(考虑3x3x3矩阵):

        row 1: v[0][0][0],v[0][0][1],v[0][0][2]
        row 2: v[0][1][0],v[0][1][1],v[0][1][2]
        row 3: v[0][2][0],v[0][2][1],v[0][2][2]
        row4: v[1][0][0],v[1][0][1],v[1][0][2] 
        ...

像这样,我必须分别告知用户x和y尺寸的数量。不太干净,但不算大戏。

我的问题是,如何在Matlab中加载和绘制这样的数据集?值为1/0。

有没有更聪明的方法可以做到这一点?我正在从Java导出。

谢谢!

解决方法

我想不出一种可以省略存储矩阵维的方法(至少应提及其中两个)。但是,在将值存储在文件中时,我建议您甚至不要以表格格式编写它们。您需要了解的有关MATLAB的所有信息就是矩阵中元素的顺序。看一下这个例子:

$plainText = "Plain text"
$secureString = ConvertTo-SecureString $plainText -AsPlainText -Force
$quotedSecureString = "$secureString"
$plainText.GetType()
$secureString.GetType()
$quotedSecureString.GetType()

这是矩阵的样子:

M(:,:,1)=

$env:SVCUSER="testuser"
$env:SVCPASS="testpass"
$env:SITENAME="test.com"
$env:SecurePass=ConvertTo-SecureString $env:SVCPASS -AsPlainText -Force
New-LocalUser -Name "$env:SVCUSER" -Password $env:SecurePass -Description "$env:SITENAME Site User"

M(:,:,2)=

Cannot bind parameter 'Password'. Cannot convert the "System.Security.SecureString" value of type "System.String" to type "System.Security.SecureString".

M(:,:,3)=

$env:SVCUSER="testuser"
$env:SVCPASS="testpass"
$env:SITENAME="test.com"
$SecurePass=ConvertTo-SecureString $env:SVCPASS -AsPlainText -Force
New-LocalUser -Name "$env:SVCUSER" -Password $SecurePass -Description "$env:SITENAME Site User"

M(:,:,4)=

%% create a 3d matrix
% a = 1+randi(5);
% b = 1+randi(5);
% c = 1+randi(5);
a = 2; b = 3; c = 4;
M = reshape(1:a*b*c,a,b,c)

现在让我们将其写入文本文件中:

 1     3     5
 2     4     6

这是文件的内容:

2,3,4
1
2
3
4
...
21
22
23
24

现在,要读取文件:

 7     9    11
 8    10    12