“Unexpected MATLAB expression” when creating sparse graph

后端 未结 3 622
清歌不尽
清歌不尽 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:42

    Congratulations, you have found a bug in the MATLAB documentation!

    The cm = at the end belongs on the next line and is actually the output MATLAB gives you when you type

    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)
    

    MATLAB uses linebreaks to signify the end of a command unless you end the line with ..., and after the closing bracket on your second line it doesn't understand what the cm is supposed to mean ;-)

提交回复
热议问题