How to extract only certain values from a field in a structure array?
이전 댓글 표시
Hello, I am trying to output only certain values from a field in a structure array called Cells. The values I want are in the pos field, and I only want the value when the values in the Type field are equal to 1, and thus when P is 1. This is my code so far. It works in the command window and gives me all the variables, when I do not assign Cells(P).pos to a variable. But my problem is that when I assign Cells(P).pos to a variable it only gives me one value, versus for all the values P is true. How do I get all the values and still assign them to a variable? I tried to preallocate prof as an empty matrix but that didn't work either. Thanks!
P=[Cells.Type]==1;
Prof= Cells(P).pos;
채택된 답변
추가 답변 (1개)
Walter Roberson
2016년 5월 8일
P=[Cells.Type]==1;
Prof= vertcat(Cells(P).pos);
댓글 수: 1
Ahmet Cecen
2016년 5월 8일
Ooh I like this one. Sneaky.
카테고리
도움말 센터 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!