Plot legend and axis label does not display

1 vue (au cours des 30 derniers jours)
Felix Obite
Felix Obite le 19 Mar 2022
Commenté : Felix Obite le 19 Mar 2022
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')

Réponses (2)

Voss
Voss le 19 Mar 2022
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')

Star Strider
Star Strider le 19 Mar 2022
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 commentaire
Felix Obite
Felix Obite le 19 Mar 2022
Thanks a lot. I appreciate

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by