フィルターのクリア

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 日間)
Joshua
Joshua 2022 年 8 月 16 日
回答済み: Ishu 2023 年 12 月 1 日
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 件のコメント
Benjamin Thompson
Benjamin Thompson 2022 年 8 月 16 日
Neither of those two functions are part of MATLAB. What are their definitions?
Walter Roberson
Walter Roberson 2022 年 8 月 16 日
Those are part of Psychtoolbox, which has separate support mechanisms

サインインしてコメントする。

回答 (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 Center および File ExchangeTiming 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