“Unexpected MATLAB expression” when creating sparse graph

后端 未结 3 628
清歌不尽
清歌不尽 2021-01-29 14:16

I have tried following code for creating sparse graph in MATLAB:

cm = sparse([1 1 2 2 3 3 4 5],[2 3 4 5 4 5 6 6],...
     [2 3 3 1 1 1 2 3],6,6)cm =
3条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-29 14:48

    You shouldn't write the cm = part at the end. That is, when you write

    cm = sparse([1 1 2 2 3 3 4 5],[2 3 4 5 4 5 6 6],...
         [2 3 3 1 1 1 2 3],6,6)
    

    on the command line, you will get

    cm =
    
       (1,2)        2
       (1,3)        3
       (2,4)        3
       (3,4)        1
       (2,5)        1
       (3,5)        1
       (4,6)        2
       (5,6)        3
    

    This is because, you didn't write a semicolon at the end of the statement. If you don't want to see the value of cm, just add a semicolon after the closing the parentheses. In addition ... tells to write multi-line statement. You can write

    cm = sparse([1 1 2 2 3 3 4 5],[2 3 4 5 4 5 6 6],[2 3 3 1 1 1 2 3],6,6)
    

    alternatively.

提交回复
热议问题