matlab - 从结构的多个字段中提取行
问题描述
创建列向量(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]'
结构上的索引不起作用。什么是通用的方式。
解决方案
你可以简单地使用structfun
t = structfun(@(x)x(2:4),s,'UniformOutput',false)
推荐阅读
- single-sign-on - 在 Windows 和 Linux 上使用 Kerberos 进行 SSO
- xcode - Cocoapods 安装后没有源文件
- api - Telegram 使用可点击的 bot 命令发送消息
- go - ContentDisposition 类来构建文件内容配置
- javascript - 如何使用添加方法 Extjs 组件到另一个 Extjs 组件(moderntoolkit)
- android - 从 Activity 向广播接收器发送附加信息
- c# - 无论如何要隐藏行 ID 列
- python - 我如何使用 Pygame get_size()?
- html - HTML中的Button元素是什么
- flask - 从 QuerySelectField 中删除重复项