【问题标题】:the values of coordinates in matlabmatlab中的坐标值
【发布时间】:2015-08-16 11:14:00
【问题描述】:

如果我有矩阵

s = [ 0         0.4000    0.5000    0.6000    0.9000
      0.4000         0    0.3000    0.4000    0.5000
      0.5000    0.3000         0    0.5000    0.8000
      0.6000    0.4000    0.5000         0    0.6000
      0.9000    0.5000    0.8000    0.6000         0];

coordinates = [1 2; 1 3; 2 4]

然后我希望先前坐标的值为零。即 s(1,2),s(2,1),s(1,3)s(3,1),s(2,4),s(4,2) 等于 0 即我想要这个结果

0         0         0         0.6000    0.9000
0         0         0.3000    0         0.5000
0         0.3000         0    0.5000    0.8000
0.6000    0         0.5000         0    0.6000
0.9000    0.5000    0.8000    0.6000         0` 

【问题讨论】:

    标签: arrays matlab matrix coordinates


    【解决方案1】:

    这似乎是你想要的。你只需要使用sub2ind:

    s(sub2ind(size(s), coordinates(:,1), coordinates(:,2))) = 0; %// make these entries 0
    s(sub2ind(size(s), coordinates(:,2), coordinates(:,1))) = 0; %// and symmetric entries too
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-04
      相关资源
      最近更新 更多