MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   MATLAB结构中每个字段的值的子集 (https://www.labfans.com/bbs/showthread.php?t=26237)

poster 2019-12-14 20:13

MATLAB结构中每个字段的值的子集
 
假设有一个名为data的结构,其中包含data1 data2,data3,data4的字段中包含许多项。但是我想创建一个变量newdata,它具有相同的字段,但是每个字段中只有前100个项目。没有人知道没有循环或蛮力方法的快速方法吗?

data1: [3744x1 double] data2: [3744x1 double] data3: [3744x1 double] data4: [3744x1 double]

[B]回答:[/B]

使用[URL="http://www.mathworks.com/help/techdoc/ref/structfun.html"]STRUCTFUN[/URL]

newdata = structfun(@(x)x(1:100),data,'uniformOutput',false); 例:

>> data = struct('a',1:10,'b',1:10); >> newdata = structfun(@(x)x(1:3),data,'uniformOutput',false) newdata = a: [1 2 3] b: [1 2 3]

[url=https://stackoverflow.com/questions/4823637]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 23:17

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.