How can I shift a piece of text from the centre of the screen to the right by a certain number of pixels?
2 views (last 30 days)
Show older comments
I have a piece of text in the centre of the screen (a + symbol) and would like duplicate it but shift it to the right by a number of pixels so that I have two + symbols next to each other (they need to be an exact distance apart), but I don't know how to.
The code below is what I have that makes it go into the centre of the screen
Screen('TextSize', windowPtr, 50);
DrawFormattedText(windowPtr, '+', 'center', 'center', [0 0 0]);
Any help would be greatly appreciated, thanks
2 Comments
Benjamin Thompson
on 16 Aug 2022
Neither of those two functions are part of MATLAB. What are their definitions?
Walter Roberson
on 16 Aug 2022
Those are part of Psychtoolbox, which has separate support mechanisms
Answers (1)
Ishu
on 1 Dec 2023
Hi Joshua,
I understand that you are tring to plot two "+" signs, one in the centre of the screen and other shifted right by some distance. And I assume that these symbols you want to plot on a figure window.
You can use "figure" and "text" function of MATLAB to plot such texts.
symbol = '+';
distance = 20; % shift distance in pixels
% Create a figure
figure;
% Plot the first symbol at the center
text(0, 0, symbol, 'HorizontalAlignment', 'center', 'VerticalAlignment', 'middle', 'FontSize', 20);
% Plot the second symbol shifted to the right
text(distance, 0, symbol, 'HorizontalAlignment', 'center', 'VerticalAlignment', 'middle', 'FontSize', 20); % Example font size
% Set the axis limits to ensure both symbols are visible
xlim([-distance, distance]);
% Set the aspect ratio to ensure equal scaling in both x and y directions
axis equal;
To hide the axis ticks and labels use can add "axis off" in the code provided.
For more information you can refer these documentations:
Hope it helps.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!