0

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.

0

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.