zeronone
zeronone

Reputation: 3041

Extract a column vector from a sparse matrix in MATLAB?

I am new to MATLAB.

I have a sparse matrix (2649429x148) which I got through spconvert function. It is a sparse user-movie matrix. I want to get all the ratings for a particular movie. The user-id space has some gaps and is not continuous.

I tried the following

 mat     
            (967,1)                       1
           (7798,1)                       4
          (16272,1)                       2
          (21722,1)                       3
             .
             .
             .
          (11,148)                        5
          (2342432,148)                   5
          (2332332,148)                   5

 mat(:,4)      % it get the following 

            (967,1)                       1
           (7798,1)                       4
          (16272,1)                       2
          (21722,1)                       3
          (42773,1)                       3
          (48286,1)                       5
          (98649,1)                       2
         (156319,1)                       2
         (165720,1)                       2
          .........

I want to get (xxxxxx, 4) .....

How can I get a column vector of all the ratings for a particular movie?

Upvotes: 0

Views: 144

Answers (1)

Divakar
Divakar

Reputation: 221524

Check this out if it works -

[~,col1,val] = find(mat);
ratings = val(col1==4)

Upvotes: 1

Related Questions