[運算] 請問.mat filew相加

作者: riviera (Nikita~)   2019-02-15 23:07:04
請問我有多個.mat files (sample_01.mat, sample_02.mat ...etc),
每一個mat file 都是矩陣相同的 (假設是2 x 2)
請問我要如何把多個mat. files想加?
sample_01.mat = [1 2;3 4]
sample_02.mat = [2 3;4 5]
想要得到1+2 最後變成 [3 5; 7 9] 的另一個.mat file ?
謝謝
作者: shuncheng (shuncheng)   2019-02-15 23:11:00
load 處理後在儲存
作者: profyang (prof)   2019-02-16 14:25:00
load進來 看他變數是啥 然後在Matlab裡相加相加後再用save存新的.mat
作者: riviera (Nikita~)   2019-02-16 19:21:00
可是有50~60個mat files,有辦法for loop嗎?
作者: profyang (prof)   2019-02-16 21:39:00
那就要看你取名有沒有規律阿 或者你把那50個.mat放到空白資料夾 然後用dir類的抓出所有mat檔名 然後讀出來慢慢加例如 D=dir('你的資料夾位置'); 然後for迴圈裡用D(i).name之類的把一個個mat檔名叫出來load

Links booklink

Contact Us: admin [ a t ] ucptt.com