Hi, I have the following 1x10 matlab structure where all 10 elements are column vectors of varying sizes. Need to convert it to matrix as described below. Any help?

조회 수: 4 (최근 30일)
I have the following 1x10 matlab structure where all 10 elements are column vectors of varying length. I want to populate the first 10 row of a matrix of zeros of size 256x160 with this structure such that first 10 rows of the matrix are replaced by 10 column vectors values respectively. If length does not cover all 160 values it will stay 0 as before. Could you kindly outputhelp? Thank you so much.

채택된 답변

Voss
Voss 2022년 9월 21일
If S is your struct array and M is your matrix of zeros:
for ii = 1:numel(S)
M(ii,1:numel(S(ii).times)) = S(ii).times;
end
  댓글 수: 1
sam
sam 2022년 9월 21일
Hi Voss, it works. Thank you so much. By the way, you have any idea how can I do the same task without having the initial matrix of zeros defined. Actually I'm planning to keep the structure values only in my outcome matrix and no zeros.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by