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

poster 2019-12-10 20:41

MATLAB:将两个数组转换为稀疏矩阵
 
我在寻找将两个数组转换为稀疏矩阵的命令或技巧。这两个数组包含x值和y值,它们在笛卡尔坐标系中给出坐标。我想对坐标进行分组,如果值在x轴和y轴上的某个值之间。

% MATLAB x_i = find(x > 0.1 & x < 0.9); y_i = find(y > 0.4 & y < 0.8); %Then I want to find indicies which are located in both x_i and y_i 有一个简单的方法可以解决这个小窍门吗?



[B]回答:[/B]

假设x和y具有相同的形状(如果它们是坐标,则形状应相同),您可以简单地编写

commonIndices = find(x > 0.1 & x < 0.9 & y > 0.4 & y < 0.8); 如果您希望找到一种通用的方法来查找两个列表共有的数字,则可以使用相交

commonEntries = intersect(x_i,y_i);

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


所有时间均为北京时间。现在的时间是 00:21

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