Extract partial data from vectors in structure

I have a structure containing multiple fields of size 1XN and 3XN. I'm looking for a simple way to extract partial data, e.g. the new structure will contain the same fields as the original, but of sizes 1XN-x and 3XN-x.
Thanks.

 採用された回答

Stephen23
Stephen23 2019 年 11 月 28 日

0 投票

>> S.A = 0:3;
>> S.B = 4:9
S =
scalar structure containing the fields:
A =
0 1 2 3
B =
4 5 6 7 8 9
>> x = 2;
>> Z = structfun(@(v)v(:,1:end-x),S,'UniformOutput',false)
Z =
scalar structure containing the fields:
A =
0 1
B =
4 5 6 7

2 件のコメント

yonatan s
yonatan s 2019 年 11 月 28 日
Thanks. Is it possible to do the same using a logical array, instead of 1:end-x?
Stephen23
Stephen23 2019 年 11 月 28 日
"Is it possible to do the same using a logical array, instead of 1:end-x?"
Yes.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeStructures についてさらに検索

製品

リリース

R2018b

タグ

質問済み:

2019 年 11 月 28 日

コメント済み:

2019 年 11 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by