Sparse matrix plot matlab

后端 未结 2 1378
Happy的楠姐
Happy的楠姐 2021-01-23 15:31

I have a 5000 *5000 sparse matrix with 4 different values. I want to visualise the nonzero elements with 4 different colors such that I can recognise the ratio of this values an

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-23 16:05

    Now i can answer the first part of the question. I suppose you need to do something like

    sum(histc(A, unique(A)),2)

    to count the number of unique values in the matrix.

    temp = histc(A, unique(A)) "is a matrix of column histogram counts." So you get the counts of all values of unique(A) as they appear in A columns.

    I'm doing stat = sum(temp,2) to get counts of all values of unique(A) in the whole matrix.

    Then you can use the code proposed from @Dan to visualize the result.

    hold all; 
    u=unique(A);
    for i = 1:length(stat) 
    plot(u(i), stat(i)/max(stat), '*');
    end
    

    Please clarify what kind of relationship between the values do you mean?

提交回复
热议问题