필터 지우기
필터 지우기

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

조회 수: 1 (최근 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