形状変換

8 views (last 30 days)
sz
sz on 29 Nov 2021
Answered: Atsushi Ueno on 29 Nov 2021
現在18×231250のデータが19個あります。
この18×231250×19のマトリックスを18×231250に形状変換したいです。
18×231250のデータを1個取り出すようにしたいです。(18×231250×1にする)
18×231250×19のデータをAなどと置いてスクリプトを送っていただきたいです。
reshapeを使うと思うのですが理解が出来ていないのでスクリプトも送っていただけると嬉しいです。
よろしくお願いいたします。

Accepted Answer

Atsushi Ueno
Atsushi Ueno on 29 Nov 2021
A = zeros(18,231250,19); % 18×231250×19のマトリックスを18×231250に形状変換
for index = 1:size(A,3) % size(A,3)=19(Aの三番目の次元の数)なのでindex=1~19まで走査する
B = A(:,:,index); % 18×231250のデータ(index番目)を1個取り出す
size(B)
... % この後取り出した18×231250のデータを処理する
end
ans = 1×2
18 231250
ans = 1×2
18 231250
ans = 1×2
18 231250
ans = 1×2
18 231250
ans = 1×2
18 231250
ans = 1×2
18 231250
ans = 1×2
18 231250
ans = 1×2
18 231250
ans = 1×2
18 231250
ans = 1×2
18 231250
ans = 1×2
18 231250
ans = 1×2
18 231250
ans = 1×2
18 231250
ans = 1×2
18 231250
ans = 1×2
18 231250
ans = 1×2
18 231250
ans = 1×2
18 231250
ans = 1×2
18 231250
ans = 1×2
18 231250
>reshapeを使うと思うのですが
⇒配列の形状変換(変更)というと、変換前後の要素数が変わらない変換の事を言います。
今やりたい事は3次元の行列から2次元のスライス1枚を取り出す事で、要素数はn分の1に減ります。

More Answers (0)

Categories

Find more on 行列および配列 in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!