Conconate arrays horizontally in an automatic manner

2 views (last 30 days)
Hi,
I have the following matrix:
features_arm.(subjects{q}).(taskname{i}).AccNorm
taskname contains RF1, RF2 & RF3. (reach forward)
I would like to use
horzcat(features_arm.(subjects{q}).RF1.AccNorm,features_arm.subjects{q}).RF2.AccNorm,features_arm.subjects{q}).RF3.AccNorm)
However, not all subjects have RF1, RF2 and RF3 (eg some only have RF1 and RF2).
Would there be an elegant way to conconate the data for all tasks without having to check this manually for each subject?
(I was thinking something in the area of 'RF*', but I am failing to figure something out that works)
Thanks

Answers (1)

dpb
dpb on 28 Apr 2022
"The MATLAB way" around such problems is to not create sequentially-named variables of the type RFn but use either cell arrays or dynamic field names to write generic code.
See the content of the old MATLAB FAQ Wiki at <FAQ#How_can_I_create_variables_A1.2C_A2.2C....>
There used to be a link in the doc to similar content but they've changed the organization and I now no longer find that so easily...

Categories

Find more on Function Creation in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!