How can I shift a piece of text from the centre of the screen to the right by a certain number of pixels?

2 vues (au cours des 30 derniers jours)
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 commentaires
Benjamin Thompson
Benjamin Thompson le 16 Août 2022
Neither of those two functions are part of MATLAB. What are their definitions?
Walter Roberson
Walter Roberson le 16 Août 2022
Those are part of Psychtoolbox, which has separate support mechanisms

Connectez-vous pour commenter.

Réponses (1)

Ishu
Ishu le 1 Déc 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.

Catégories

En savoir plus sur Timing and presenting 2D and 3D stimuli dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by