Conconate arrays horizontally in an automatic manner

조회 수: 2 (최근 30일)
Inti Vanmechelen
Inti Vanmechelen 2022년 4월 28일
답변: dpb 2022년 4월 28일
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

답변 (1개)

dpb
dpb 2022년 4월 28일
"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...

카테고리

Help CenterFile Exchange에서 Function Creation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by