Store the structure fields generated in a for loop into a vector

조회 수: 2 (최근 30일)
Karthik Brs
Karthik Brs 2015년 10월 27일
편집: Stephen23 2015년 10월 27일
Hello everyone, I have a small problem here, my 1*2 struct of the name 'ord' has 7 fields as can be seen in the figure.
This structure is generated in a 'for' loop. So, depending on the looping condition it can also be a 1*3... 1*n struct. I am required to create a vector which contains the field data of 'rpm' which gets generated each time the 'for' loop runs. In other words, I simply want to store ord(1).rpm, ord(2).rpm and so on.. into vectors. In this case it is just a 1*2 struct, I am looking for a code which can store the data generated in the rpm field as and when it gets generated while in loop!
Thank you in advance!

채택된 답변

Thorsten
Thorsten 2015년 10월 27일
편집: Thorsten 2015년 10월 27일
Use a cell array:
RPM{i} = ord.rpm;
  댓글 수: 1
Stephen23
Stephen23 2015년 10월 27일
편집: Stephen23 2015년 10월 27일
Rather than doing this one element-at-a-time and extending the cell array, the most efficient answer is to get all of the values into one cell array like this:
{ord.rpm}
And read this to know how it works:

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

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