Calling text file

39 views Asked by At

if i have text file that has three column say

                                           1 2 1
                                           3 1 1
                                           2 3 1

and also have a matrix s =

                    [0.3  0.4   0.6
                     0.1  0.5  0.7
                     0.2  0.11  0.9]

firstly: with respect to text file, i want to consider first column as i and second column as j then if the third column equal 1 then put its corresponding value in matrix s in new array say A else put remaining value in matrix s in new another array say B.

i.e i want this result

A=[0.4, 0.2, 0.7] B=[0.3, 0.6, 0.1, 0.5, 0.11, 0.9]

1

There are 1 answers

0
Asmaa Daoud On
coordinates = [1 2 1
               3 1 1
               2 3 1];
s =  [0.3  0.4   0.6
      0.1  0.5   0.7
      0.2  0.11  0.9];

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

A = s(linindices)

B = s(setdiff(1:numel(s), linindices))