سؤال

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