Retrieve a vector from a field of a structure with certain length
1 view (last 30 days)
Show older comments
Hi everyone!
I would like to retrieve a vector from a field of a structure with certain length and I would like to avoid loops. That is. I have the following structure:
Problem.phases(1).path.nonLinear(1).buffer.include = 1;
Problem.phases(1).path.nonLinear(2).buffer.include = 0;
And I would like to retrieve an array for the different nonLinear include fields as
Array = [1;0]
So far, I have been trying with the following command:
Problem.phases(1).path.nonLinear.buffer.include
But it gives the following Error:
Expected one output from a curly brace or dot indexing expression, but there were 2 results.
Anyone knows how this could be solved?
Regards,
Guillermo
0 Comments
Answers (1)
Stephen23
on 21 Oct 2019
Edited: Stephen23
on 21 Oct 2019
>> Problem.phases(1).path.nonLinear(1).buffer.include = 1;
>> Problem.phases(1).path.nonLinear(2).buffer.include = 0;
Method one: temporary variable:
>> tmp = [Problem.phases(1).path.nonLinear.buffer];
>> mat = [tmp.include]
mat =
1 0
Method two: arrayfun:
>> fun = @(s)s.buffer.include;
>> mat = arrayfun(fun,Problem.phases(1).path.nonLinear)
mat =
1 0
See also:
0 Comments
See Also
Categories
Find more on Data Types in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!