首页 > 解决方案 > 从结构的多个字段中提取行

问题描述

创建列向量(100 行)的结构(25 个字段)。如何提取其特定行。例如,

s.a=[1 2 3 4 5 6]'
s.b=[5 2 8 1 0 4]'
s.c=[9 7 0 1 3 5]'
% 2 to 4 rows to be extracted
% expected output
t.a=[2 3 4]'
t.b=[2 8 1]'
t.c=[7 0 1]'

结构上的索引不起作用。什么是通用的方式。

标签: matlabindexingstructreferencecell-array

解决方案


你可以简单地使用structfun

t = structfun(@(x)x(2:4),s,'UniformOutput',false)

推荐阅读