Plot legend and axis label does not display

5 ビュー (過去 30 日間)
Felix Obite
Felix Obite 2022 年 3 月 19 日
コメント済み: Felix Obite 2022 年 3 月 19 日
Plot legend and axis label does not display, find codes below. Can anyone help?, Also, i would like to number each point PU(1, to 20) and SU(1 to 20) similar to the attached file.
%% 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')

回答 (2 件)

Voss
Voss 2022 年 3 月 19 日
Avoid putting extra spaces in character vectors, e.g., use:
'Vert' , 'middle' , 'Interpreter' , 'latex'
instead of:
'Vert' , ' middle ' , ' Interpreter ' , ' latex '
(MATLAB doesn't recognize ' Interpreter ' to be the same as 'Interpreter', for instance.)
%% 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
Felix Obite 2022 年 3 月 19 日
Many thanks. I appreciate

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


Star Strider
Star Strider 2022 年 3 月 19 日
Spaces are significant in name-value pair arguments, so ' Interperter ' will not be recognised.
%% 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')
They display now!
.
  1 件のコメント
Felix Obite
Felix Obite 2022 年 3 月 19 日
Thanks a lot. I appreciate

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

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by