Question

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.

No correct solution

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top