poster
2019-12-10, 20:41
我在寻找将两个数组转换为稀疏矩阵的命令或技巧。这两个数组包含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 有一个简单的方法可以解决这个小窍门吗?
回答:
假设x和y具有相同的形状(如果它们是坐标,则形状应相同),您可以简单地编写
commonIndices = find(x > 0.1 & x < 0.9 & y > 0.4 & y < 0.8); 如果您希望找到一种通用的方法来查找两个列表共有的数字,则可以使用相交
commonEntries = intersect(x_i,y_i);
更多&回答... (https://stackoverflow.com/questions/2724869)
% 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 有一个简单的方法可以解决这个小窍门吗?
回答:
假设x和y具有相同的形状(如果它们是坐标,则形状应相同),您可以简单地编写
commonIndices = find(x > 0.1 & x < 0.9 & y > 0.4 & y < 0.8); 如果您希望找到一种通用的方法来查找两个列表共有的数字,则可以使用相交
commonEntries = intersect(x_i,y_i);
更多&回答... (https://stackoverflow.com/questions/2724869)