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=26629)

poster 2019-12-14 20:13

MATLAB中单元格数组的交集
 
我需要确定数组单元中所有单元的交集。我使用这样的命令:

temp(j-1)={6 7 8 9 10}; temp(j)= {8 9 10}; inter = cellfun(@intersect,temp(j-1),temp(j),'UniformOutput', false) ; 在输出中,我得到:

inter={0189} 我应该怎么做才能得到{8 9 10}?

我必须将inter用作另一个矩阵中索引的向量。



[B]回答:[/B]

我可以看到的唯一方法是,如果您实际上得到的是inter=' 0189'因为您的单元格包含字符串,那么您会得到诸如inter={0189} 。如果是这样,则可以改成这样的交点:

>> temp = {'6 7 8 9 10''8 9 10'}温度= '6 7 8 9 10''8 9 10'>> inter =相交(str2num(temp {1}),str2num(temp {2}))间= 8 9 10我不得不问,为什么不将数据存储在数字矢量而不是字符串中?



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


所有时间均为北京时间。现在的时间是 09:07

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