# 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 日間)
Felix Obite 2022 年 3 月 21 日
コメント済み: Voss 2022 年 3 月 21 日
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' )
##### 1 件のコメント表示非表示 なし
Felix Obite 2022 年 3 月 21 日
many thanks, working perfectly now

サインインしてコメントする。

### 採用された回答

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')
##### 2 件のコメント表示非表示 1 件の古いコメント
Voss 2022 年 3 月 21 日
You're welcome!

サインインしてコメントする。

### カテゴリ

Find more on Descriptive Statistics and Visualization in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by