问题
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