Adding legend to plot window before actually plotting

3 ビュー (過去 30 日間)
Thomas
Thomas 2014 年 1 月 22 日
回答済み: Walter Roberson 2014 年 1 月 22 日
I have written a timer object function which updates a plot every 10ms. The plot window is all set up before the first timerFCN iteration. It basically plots 2 sets of data (one red line and one blue line with respect to time). I need to add a legend to this plot. Is there somehow i create a custom legends (i.e. define my own linestyle and linecolour for the legend). Since it only starts plotting once the first timerFcn runs, if i try to add a legend before this, it comes up with Warning: Plot empty.
I could add the legend in the timerFcn code section, but since its running every 10ms, just running that one extra line will cause my code to run a bit slower, which i cant have.
Thanks

採用された回答

Walter Roberson
Walter Roberson 2014 年 1 月 22 日
Create the two lines ahead of time, with the appropriate color and marker, and with [] as their XData and YData. You can then legend(). After that, as you go, update the XData and YData properties of the two lines to reflect the incoming data.

その他の回答 (1 件)

Nitin
Nitin 2014 年 1 月 22 日
Did you try to go in Edit-> Figure Properties in the plot window?

カテゴリ

Help Center および File ExchangeLegend についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by