필터 지우기
필터 지우기

Assign an array of structs to a cell

조회 수: 7 (최근 30일)
Jerry Olup
Jerry Olup 2017년 11월 16일
댓글: Jerry Olup 2017년 11월 17일
Hi, I have a variable sized array of structs that I read and want to assign to cell within a cell array. I found a results for "Conversion to cell from struct is not possible." in prior questions but that maps a single struct to a single cell. I would like to be able to store an array of structs to a cell. Is that possible? How? Thanks, Jerry
  댓글 수: 7
Jerry Olup
Jerry Olup 2017년 11월 17일
Stephen, >> Beginners often import data as string because they do not use the importing tools very effectively.
Ah, regarding importing of data:
The data is mixed between numbers (all modes, literally) and strings. It is also variable length with fields missing or having a few modes (including numeric or string, causing decisions in interpretation). That's why I ran it all as strings (with a lot, hence the ..., of code omitted). from that I can parse variations of the file effectively.
This imports all data in a few mins, so I am satisfied with the performance.
It's not regular or academic data...!
The code excerpts are meant to point out that this is storing an array of structs into a single cell.
Thanks, Jerry
Stephen23
Stephen23 2017년 11월 17일
편집: Stephen23 2017년 11월 17일
"However I am trying to assign an array of structures to a single cell."
I still do not see what the problem is. Any variable can be allocated to a cell, the fact your structure is non-scalar is irrelevant. Here is a non-scalar structure array being allocated to a cell:
>> S(1).data = 1;
>> S(2).data = 3;
>> C{1} = S;
That test code throws no errors, no problems doing exactly what you state: "assign an array of structures to a single cell."
"Instead I hav to access each structure through dot indexing"
You put the data into an structure yourself! How else would you expect to access it?

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

채택된 답변

Stephen23
Stephen23 2017년 11월 17일
편집: Stephen23 2017년 11월 17일
In your example code you need to change the indexing into the cell array from i to k:
carray{k} = results;
  댓글 수: 2
Jerry Olup
Jerry Olup 2017년 11월 17일
ugh, yes, thanks!
Jerry Olup
Jerry Olup 2017년 11월 17일
And... tested, so it's fine to store any data in cell as expected. Simple indexing error. Thx again.

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

추가 답변 (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