coordinate data in the text command

3 views (last 30 days)
hans
hans on 16 Dec 2021
Commented: hans on 16 Dec 2021
Is it possible to somehow put both, x- and y-coordinate, with a single variable of two fields into the location fields of the text-command?
instead of :
loc = [0.5,0.5];
figure; text(loc(1),loc(2),'a')
something like
Is it possible to somehow put both, x- and y-coordinate, into the location fields of the text-command?
instead of :
loc = [0.5;0.5];
figure; text(loc,'a')

Accepted Answer

Rik
Rik on 16 Dec 2021
You have two options that I'm aware of:
  1. Write a wrapper function that will split your vector as approriate.
  2. Use a comma separated list: loc=[0.5;0.5];loc=num2cell(loc);text(loc{:},'a')
  13 Comments
hans
hans on 16 Dec 2021
May be to tell it shorter:
It seems to me comma separated lists have their dominating area of application assigning values to arrays and to fill argument lists of commands/functions

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 16 Dec 2021
text('String', 'a', 'Position', loc)
  1 Comment
hans
hans on 16 Dec 2021
Thank You for Your contribution.
I'm still confused, why the text command accept this syntax of loc after the 'Position' switch, but not as the first entry of the text command
Why does the first position require a cell variable
the second requires a vector
loc = {0.5;0.5}
figure
text(loc{:},'a')
clear
loc = [0.5 0.5]
figure
text('Position', loc, 'String','a');

Sign in to comment.

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by