Retrieve a vector from a field of a structure with certain length

조회 수: 1 (최근 30일)
Guillermo Joaquín Dominguez Calabuig
편집: Stephen23 2019년 10월 21일
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

답변 (1개)

Stephen23
Stephen23 2019년 10월 21일
편집: Stephen23 2019년 10월 21일
>> 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:

카테고리

Help CenterFile Exchange에서 Data Types에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by