Input
hhh={{1,11},{2,22},{3,33},{4,44}}
Intended output
11 22 33 44
P.s. hhh{1}{2}
, hhh{2}{2}
, hhh{3}{2}
and hhh{4}{2}
returns the right output but I am trying to find how to do it like hhh{:}{2}
.
One way would be to use cellfun
n=2
cellfun(@(x)(x{n}), hhh)
Which is essentially just a short hand for a for loop.
Or another possibly which is completely vectorized but will be more difficult to generalize is to first linearize and then select every second element:
temp = [hhh{:}]
[temp{2:2:end}]
Octave allows this in one line (Matlab does not unfortunately):
[hhh{:}](2:2:end)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With