Get values of given coordinates in Matlab -


if have given coordinates [1 2; 4 5] ,

s = [      0.0    0.4    0.5    0.6    0.9      0.4    0.0    0.3    0.4    0.5      0.5    0.3    0.0    0.5    0.8      0.6    0.4    0.5    0.0    0.6      0.9    0.5    0.8    0.6    0.0      ] 

i want following results:

  • a should contain values of coordinates , inverse coordinates. i.e in example, a contains values of (1,2), (2,1), (4,5), (5,4). is: a=[0.4, 0.4, 0.6, 0.6].

  • b contains remaining values, b=[0, 0.5, 0.6, 0.9, 0, 0.3, 0.4, 0.5, 0.5, 0.3, 0, 0.5, 0.8, 0.4, 0.5, 0, 0.9, 0.5, 0.8, 0.6, 0].

so far have following code:

linindices = sub2ind(size(s), coordinates(:, 1), coordinates(:, 2))';  = s(linindices) b = s(setdiff(1:numel(s), linindices)) 

but calculates a=[0.4,0.6]. how can inverse coordinates too?

actually, there. thing getting inverse coordinates- can command fliplr.

here can see how can done, whole code , results. critic line av:

    c=[1 2; 4 5];     s=[0 0.4 0.5 0.6 0.9     0.4 0 0.3 0.4 0.5     0.5 0.3 0 0.5 0.8     0.6 0.4 0.5 0 0.6     0.9 0.5 0.8 0.6 0];     av=[c; fliplr(c)]     ac=s(sub2ind(size(s),a(:,1),a(:,2)))     b=s(setdiff(1:numel(s),sub2ind(size(s),a(:,1),a(:,2))))'   av =       1     2      4     5      2     1      5     4   ac =      0.4000     0.6000     0.4000     0.6000   b =           0     0.5000     0.6000     0.9000          0     0.3000     0.4000     0.5000     0.5000     0.3000          0     0.5000     0.8000     0.6000     0.4000     0.5000          0     0.9000     0.5000     0.8000          0 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -