659
edits
Carandraug (talk | contribs) m (→Problem: fix code, must be cell array) |
Carandraug (talk | contribs) m (→Retrieve a field value from all entries in a struct array: fixing code, leftoverd from older example) |
||
Line 24: | Line 24: | ||
Returning all values in a comma separated lists allows you to make anything out of them. If numbers are expected, create a matrix by enclosing them in square brackets. But if strings are to be expected, a cell array can also be easily generated with curly brackets | Returning all values in a comma separated lists allows you to make anything out of them. If numbers are expected, create a matrix by enclosing them in square brackets. But if strings are to be expected, a cell array can also be easily generated with curly brackets | ||
{samples(:). | {samples(:).patient} | ||
You are also not limited to return all elements, you may use logical indexing from other fields to get values from the others: | You are also not limited to return all elements, you may use logical indexing from other fields to get values from the others: | ||
[samples([samples(:).age] > 34).tube] ## return tube numbers from all samples from patients older than 34 | [samples([samples(:).age] > 34).tube] ## return tube numbers from all samples from patients older than 34 | ||
[samples(strcmp({samples(:).protein}, "CDK2").tube] | [samples(strcmp({samples(:).protein}, "CDK2")).tube] ## return all tube numbers for protein CDK2 | ||
== Input/output == | == Input/output == |