split struct based on description
조회 수: 4 (최근 30일)
이전 댓글 표시
Hi. How do you subdivide the struct into multiple structs as shown in the figure?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1411039/image.png)
댓글 수: 0
채택된 답변
Stephen23
2023년 6월 15일
C = {S.SeriesDescription};
S_scout = S(strcmpi(C,'Scout'))
S_serie = S(strcmpi(C,'Serie'))
S_stand = S(strcmpi(C,'Standard'))
If you want to do it "automatically" for multiple different strings:
Note that splitting up data is rarely a good approach to processing data. Usually keeping data together makes it easier to process.
댓글 수: 2
Stephen23
2023년 6월 15일
편집: Stephen23
2023년 6월 15일
"How can I do it if I want to directly use the names in the cell and create the substructures simultaneously?"
If you really want to force yourself into writing slow, complex, inefficient, obfuscated, buggy code that is harder to debug, you can find plenty of examples linked here:
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!