문제

I am representing polynomials p and q as a structure array in the form:

p=struct('exponent',{2,3},'coeff',{1,1})
q=struct('exponent',{1,5,6,7},'coeff',{1,1,1,1})

I need to be able to select all the exponent elements of q for use in a function. I have attempted to do this by a=q(1,(:)).exponent

I want a to become the array [1,5,6,7]. Thank you for any help in advance.

올바른 솔루션이 없습니다

다른 팁

It's as simple as:

a = [q.exponent];

Accessing a field of a struct array like that returns a list of the values for each element in the array, which you can just catch in a concatenation operator.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top