필터 지우기
필터 지우기

Concatenating matrices in a structure with same size into a 3D array.

조회 수: 1 (최근 30일)
Hello,
I have a structure consisting of 25 matrices, all of the same sizes, 5750 x 360. I am trying to figure out how I can concatenate this array in the third dimension so that I can get an array of 5750 x 360 x 25.
x_mat.mat1=rand(100, 5);
x_mat.mat2=rand(100, 5);
x_mat.mat3=rand(100, 5);
x_mat.mat4=rand(100, 5);
structfun(@(x) cat(3, x), x_mat, UniformOutput=false)
ans = struct with fields:
mat1: [100×5 double] mat2: [100×5 double] mat3: [100×5 double] mat4: [100×5 double]
I've tried this, but it returns the same structure.
Thank you in advance. :-)

채택된 답변

Bruno Luong
Bruno Luong 2023년 8월 21일
x_mat.mat1=rand(100, 5);
x_mat.mat2=rand(100, 5);
x_mat.mat3=rand(100, 5);
x_mat.mat4=rand(100, 5);
c=struct2cell(x_mat);
A=cat(3,c{:});
size(A)
ans = 1×3
100 5 4

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by