arrays - vectorize data from struct in matlab -



arrays - vectorize data from struct in matlab -

i have created struct by:

a(1).x = {[1.1 5 8], [3 5 6]}; a(2).x = {[3.1 0 4], [9 8 7]};

and wish obtain array value [1.1 3.1].

i have tried:

a.x{1}(1,1) field reference multiple construction elements followed more reference blocks error.

any ideas please?

the syntax error tells cannot farther sub-reference within multiple struct elements. so, obvious one-liner—much slower for loop—that saves memory be:

arrayfun(@(y) y.x{1}(1), a)

just compare performance, loop-based version

function = my_extractor(s) = zeros(size(s)); n = numel(s); k = 1:n a(k) = s(k).x{1}(1); end; end

arrays matlab

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -