Why is indexing a sparse matrix not behaving how I would expect?
I am trying to understand someone else’s code so I don’t entirely understand what is happening (it is trying to fill in missing values) but this is what I am observing. I have the following sparse matrix:
val =
(1,41) 1
(1,42) -2
(2,42) 1
(1,43) 1
(2,43) -2
(3,43) 1
(2,44) 1
(3,44) -2
(3,45) 1
(4,45) 1
(4,46) -2
(5,46) 1
(4,47) 1
(5,47) -2
(6,47) 1
(5,48) 1
(6,48) -2
(6,49) 1
(7,53) 1
(7,54) -2
(8,54) 1
(7,55) 1
(8,55) -2
(9,55) 1
(8,56) 1
(9,56) -2
(10,56) 1
(9,57) 1
(10,57) -2
(10,58) 1
I also have a kown list of indexes that is almost continuous from 1:100 but excludes index numbers 43, 47, 55, 56.
When I try to index
sparse(:,known_list);
I would expect to get a list excluding all the unknown values 43, 47, 55, 56. So that I would have something like this:
val =
(1,41) 1
(1,42) -2
(2,42) 1
(2,44) 1
(3,44) -2
(3,45) 1
(4,45) 1
(4,46) -2
(5,46) 1
(5,48) 1
(6,48) -2
(6,49) 1
(7,53) 1
(7,54) -2
(8,54) 1
(9,57) 1
(10,57) -2
(10,58) 1
But instead I get:
ans =
(1,41) 1
(1,42) -2
(2,42) 1
(2,43) 1
(3,43) -2
(3,44) 1
(4,44) 1
(4,45) -2
(5,45) 1
(5,46) 1
(6,46) -2
(6,47) 1
(7,51) 1
(7,52) -2
(8,52) 1
(9,53) 1
(10,53) -2
(10,54) 1
I can’t make head or tails of the logic Matlab is using!!! I thought I understood sparse matrixes, but maybe there is something I am not getting!?!?I am trying to understand someone else’s code so I don’t entirely understand what is happening (it is trying to fill in missing values) but this is what I am observing. I have the following sparse matrix:
val =
(1,41) 1
(1,42) -2
(2,42) 1
(1,43) 1
(2,43) -2
(3,43) 1
(2,44) 1
(3,44) -2
(3,45) 1
(4,45) 1
(4,46) -2
(5,46) 1
(4,47) 1
(5,47) -2
(6,47) 1
(5,48) 1
(6,48) -2
(6,49) 1
(7,53) 1
(7,54) -2
(8,54) 1
(7,55) 1
(8,55) -2
(9,55) 1
(8,56) 1
(9,56) -2
(10,56) 1
(9,57) 1
(10,57) -2
(10,58) 1
I also have a kown list of indexes that is almost continuous from 1:100 but excludes index numbers 43, 47, 55, 56.
When I try to index
sparse(:,known_list);
I would expect to get a list excluding all the unknown values 43, 47, 55, 56. So that I would have something like this:
val =
(1,41) 1
(1,42) -2
(2,42) 1
(2,44) 1
(3,44) -2
(3,45) 1
(4,45) 1
(4,46) -2
(5,46) 1
(5,48) 1
(6,48) -2
(6,49) 1
(7,53) 1
(7,54) -2
(8,54) 1
(9,57) 1
(10,57) -2
(10,58) 1
But instead I get:
ans =
(1,41) 1
(1,42) -2
(2,42) 1
(2,43) 1
(3,43) -2
(3,44) 1
(4,44) 1
(4,45) -2
(5,45) 1
(5,46) 1
(6,46) -2
(6,47) 1
(7,51) 1
(7,52) -2
(8,52) 1
(9,53) 1
(10,53) -2
(10,54) 1
I can’t make head or tails of the logic Matlab is using!!! I thought I understood sparse matrixes, but maybe there is something I am not getting!?!? I am trying to understand someone else’s code so I don’t entirely understand what is happening (it is trying to fill in missing values) but this is what I am observing. I have the following sparse matrix:
val =
(1,41) 1
(1,42) -2
(2,42) 1
(1,43) 1
(2,43) -2
(3,43) 1
(2,44) 1
(3,44) -2
(3,45) 1
(4,45) 1
(4,46) -2
(5,46) 1
(4,47) 1
(5,47) -2
(6,47) 1
(5,48) 1
(6,48) -2
(6,49) 1
(7,53) 1
(7,54) -2
(8,54) 1
(7,55) 1
(8,55) -2
(9,55) 1
(8,56) 1
(9,56) -2
(10,56) 1
(9,57) 1
(10,57) -2
(10,58) 1
I also have a kown list of indexes that is almost continuous from 1:100 but excludes index numbers 43, 47, 55, 56.
When I try to index
sparse(:,known_list);
I would expect to get a list excluding all the unknown values 43, 47, 55, 56. So that I would have something like this:
val =
(1,41) 1
(1,42) -2
(2,42) 1
(2,44) 1
(3,44) -2
(3,45) 1
(4,45) 1
(4,46) -2
(5,46) 1
(5,48) 1
(6,48) -2
(6,49) 1
(7,53) 1
(7,54) -2
(8,54) 1
(9,57) 1
(10,57) -2
(10,58) 1
But instead I get:
ans =
(1,41) 1
(1,42) -2
(2,42) 1
(2,43) 1
(3,43) -2
(3,44) 1
(4,44) 1
(4,45) -2
(5,45) 1
(5,46) 1
(6,46) -2
(6,47) 1
(7,51) 1
(7,52) -2
(8,52) 1
(9,53) 1
(10,53) -2
(10,54) 1
I can’t make head or tails of the logic Matlab is using!!! I thought I understood sparse matrixes, but maybe there is something I am not getting!?!? sparse, interpolation, nan MATLAB Answers — New Questions