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)

1 回表示 (過去 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 Center および File ExchangeLine Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by