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

3 次查看(过去 30 天)
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

回答(1 个)

Ishu
Ishu 2023-12-1
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.

类别

Help CenterFile Exchange 中查找有关 Timing and presenting 2D and 3D stimuli 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by