필터 지우기
필터 지우기

Save arrays in a structure

조회 수: 17 (최근 30일)
Abderrahmane DADA
Abderrahmane DADA 2019년 5월 15일
댓글: madhan ravi 2019년 5월 16일
Hi.
I have written an algorithm that computes an array "b" for each ith iteration [i={1,2,3,4}], and I would like to save those arrays in a structure called "A".
How to save those arrays in the structure "A" where its elements are function of "i", i.e, A = {b1, b2,b3, b4} and to get b1 for instance, one would have to type A.b1.
Regards.
  댓글 수: 2
Stephen23
Stephen23 2019년 5월 16일
편집: Stephen23 2019년 5월 16일
Note that using a non-scalar structure would be more efficient than generating fieldnames.
Indexing is much faster and less buggy than messing around forcing meta-data (i.e. that index) into some fieldnames.
madhan ravi
madhan ravi 2019년 5월 16일
Agree with Stephen.

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

채택된 답변

madhan ravi
madhan ravi 2019년 5월 15일
doc cell2struct
  댓글 수: 3
madhan ravi
madhan ravi 2019년 5월 16일
편집: madhan ravi 2019년 5월 16일
A=struct; % an example
for k=1:5
A.(sprintf('b%d',k))=rand(5);
end
Abderrahmane DADA
Abderrahmane DADA 2019년 5월 16일
Thanks a lot Madhan.
That's exactly what I was looking for.

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

추가 답변 (0개)

카테고리

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

태그

제품


릴리스

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by