我試圖將所有這些2d矩陣我在.dat文件中合併成一個3d矩陣。如何從.dat文件中取出一堆2d矩陣並將它們放入一個大的3d矩陣中?
那麼我迄今所做的是:
for (i=1:40) //There are 40 of these files
fileName = ['Solutionm1.dat/Solution' num2str(i-1) '.dat'] //This line sets a file name
f=fopen(fileName,'r') //I'm just opening the file now
A{i}=fread(f,'double') //Now I'm converting the binary file into a matlab matrix
B{i}=reshape(A{i},41,21) //Now I'm putting it into the shape that I want (I don't know of a better way to read binary files)
fclose all
end
最後,我想用norm((insert 3d matrix here),2)
我遇到的問題是,藉此3D矩陣的L2規範我只是不知道如何將我剛剛製作的所有矩陣組合成一個大的3D矩陣。
解決方案
使用
T(:,:,i)=B{i}
或使用
T=cat(3,B{:})
續問題
這並不是現在的工作:
norm(T,2) //Should compute the L2 norm of my 3D matrix, right?
這可能是出了這個問題,雖然範圍的...
據我瞭解,我認爲規範必須建立在一個二維矩陣使用。
啊!這也適用!接受答案! – Mechy
嗯,標準(T,2)不起作用的原因是什麼? – Mechy
對不起,我頭上沒有答案,現在需要去開會。 –