How to extract only certain values from a field in a structure array?
Afficher commentaires plus anciens
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;
Réponse acceptée
Plus de réponses (1)
Walter Roberson
le 8 Mai 2016
P=[Cells.Type]==1;
Prof= vertcat(Cells(P).pos);
1 commentaire
Ahmet Cecen
le 8 Mai 2016
Ooh I like this one. Sneaky.
Catégories
En savoir plus sur Matrices and Arrays dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!