plot legend and axis does not display, also i need to assign numbers to each of the points such as PU(1 to 20) and SU(1 TO 20)

2 次查看(过去 30 天)
Find the codes below, i run in matlab and plot legend does not display. Also i need to assign numbers to each points exactly like the attached sample file. Can anybody help
%% Sample points considering a 10 × 10 area, consisting of 20 secondary usesrs (SUs) and 20 primary users (PUs) randomly distribute
SU = rand (20) * 10; % sample points
PU = rand (20) * 10; % sample points
%% figures
plot (SU (:, 1), SU (:, 2), '+ k' )
hold on
plot (PU (:, 1), PU (:, 2), '* k' )
hold off
text (SU (:, 1), SU (:, 2), compose ( '$ \\% d $' , 1: size (SU, 1)), 'Horiz' , 'left' , 'Vert' , ' middle ' , ' Interpreter ' , ' latex ' )
text (PU (:, 1), PU (:, 2), compose ( '$ \\% d $' , 1: size (PU, 1)), 'Horiz' , 'left' , 'Vert' , ' middle ' , ' Interpreter ' , ' latex ' )
legend ( 'SU' , 'PU' )

采纳的回答

Voss
Voss 2022-3-21
Avoid having extra spaces in character vectors.
MATLAB treats
' Interpreter '
differently than it treats
'Interpreter'
I removed those extra spaces below and also included a Location for the legend:
%% Sample points considering a 10 × 10 area, consisting of 20 secondary usesrs (SUs) and 20 primary users (PUs) randomly distribute
SU = rand (20) * 10; % sample points
PU = rand (20) * 10; % sample points
%% figures
plot (SU (:, 1), SU (:, 2), '+ k' )
hold on
plot (PU (:, 1), PU (:, 2), '* k' )
hold off
text (SU (:, 1), SU (:, 2), compose ( '$ \\% d $' , 1: size (SU, 1)), 'Horiz' , 'left' , 'Vert' , 'middle' , 'Interpreter' , 'latex' )
text (PU (:, 1), PU (:, 2), compose ( '$ \\% d $' , 1: size (PU, 1)), 'Horiz' , 'left' , 'Vert' , 'middle' , 'Interpreter' , 'latex' )
legend ( 'SU' , 'PU' , 'Location', 'Southwest')

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Title 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by