Create an array of structures
이전 댓글 표시
Hello!
I'm trying to create a 4x5 matrix containing a 1x3 structure in each of its cells but I can't get the result shown in the picture. I only managed to get a 9x1 structure.

position = {'corner';'edge';'corner';'edge';'inside';'edge';'corner';'edge';'corner'};
temperature = {25;25;25;25;50;25;25;25;25};
ic = {0;0;0;0;0;0;0;0;0};
PCB = [position, temperature ,ic]
cell2struct(PCB,{'position';'temperature';'ic'},1)
Does anyone know how to create it? Thank you very much!
댓글 수: 4
Most likely you are confusing the number of fields with the size of a structure element. The size and the number of fields are totally independent things. Every element of a structure is scalar, no matter how many fields it has. So your example would be a 4x5 structure (with 3 fields), and does NOT contain 1x3 structs, as your image shows.
You provide 9 data points but you want a structure with 20 elements: where are the missing data supposed to come from? What values are supposed to be placed in the other 11 structure elements?
Izan Segarra
2020년 10월 11일
Stephen23
2020년 10월 11일
"What would be the correct way to carry out the structure of 4x5?"
That depends on the format of the input data:
- Are they generated one-at-a-time in a loop (or similar), or are they available in arrays?
- Can the data arrays (if in arrays) change size? What size do the arrays use?
Possibly struct or one of the conversion functions would suit your task.
Izan Segarra
2020년 10월 11일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Programming에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!