Writing 2 variables in a legend with 2 different plots

佐手、 提交于 2020-01-25 13:16:44

问题


I want to write 2 variables in my legend.

legend('raw', 'suggested-signal: %f , suggested-filter: %f',a,b);

I know this is wrong, but I don't know how else to include 2 variable in the legend. I have a way for 1 variable but not two.


回答1:


If I get your intention correctly, you miss the sprintf:

legend('raw', sprintf('suggested-signal: %f, suggested-filter: %f',x,y));



回答2:


I would dome something like this:

legend('raw', ['suggested-signal: ' num2str(a)]', ['suggested-filter: ' num2str(b)]);



回答3:


The right answer given by EBH I just want add a detail: as you told writing legend with 2 different plot I thought about subplot, so here is the code:

figure
subplot(2,1,2)
plot(x,a1,x,a2)
legend('raw data', sprintf('suggested-signal: %f, suggested-filter: %f',10,20))

subplot(2,1,1)
plot(x,a2,x,a1)
legend('raw data' , spritf('again %f %f',10,20))
legend('raw data' , sprintf('again %f %f',10,20))



来源:https://stackoverflow.com/questions/38788015/writing-2-variables-in-a-legend-with-2-different-plots

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!