Plot several lines (looping through line styles in cell array) in Matlab

后端 未结 1 571
广开言路
广开言路 2021-01-24 07:29

I have written this loop to plot each line of results and I get the error message

Error using plot. Invalid first data argument.

So

相关标签:
1条回答
  • 2021-01-24 08:32

    You should write:

    plot(xint,test(ii,:),...
            LineSpec{ii},...
            'linewidth',2);
    

    LineSpec is a cell array, so LineSpec(ii) returns a cell, while plot asks for a character array as line properties.

    you can see the difference when you call LineSpec:

    >> LineSpec{1}
    ans =
    -y
    >> LineSpec(1)
    ans = 
        '-y'
    

    When the output is a cell then the answer is indented and has the single-quote marks.

    0 讨论(0)
提交回复
热议问题