Simplification in 2D plot for a square matrix data

Home Forums Matlab Simplification in 2D plot for a square matrix data

Tagged: ,

This topic contains 1 reply, has 2 voices, and was last updated by  cK 9 years, 9 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #505

    pankaj kumar
    Participant

    For a square matrix [M] ,with size NXN, have only element as 1 or zero. How I can plot this matrix as a 2D plot where 1 shown as red dot while zero as blue dot. A sample plot using has attached
    for i = 1:100
    for j = 1:100
    if M(i,j) == 1;
    plot(i,j,’r.’);
    hold on, grid off
    else
    if M(i,j) == 0;
    plot(i,j,’b.’,'Markersize’,2);
    end

    #513

    cK
    Keymaster

    There is a function spy() meant for visualising sparse matrices, which can also be used here. spy(M) will (only) show locations of all nonzero elements of M. You can then call the same function on ~M after holding the plot and with a different colour spec like spy(~M,'r').

    p.s. Seems like you attachment was declined. Please attach picture files only, like jpg or png.

    • This reply was modified 9 years, 9 months ago by  cK.
    • This reply was modified 9 years, 9 months ago by  cK.
    • This reply was modified 9 years, 9 months ago by  cK.
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.