How do i get the bounding rect of each word in a text (for reading eyetracking)? - matlab

For an eye tracking study i need the positions of each word in a text drawn to the window.
I can see how I can get the bounding box of the whole text as a return value using
[nx, ny, textbounds] = DrawFormattedText(win, tstring)
Is there a better way than drawing a whole sentence using this function word by word?

Something like this should do it:
teststr = {'Hello World!' ; 'How are you doing?'}
ystart = 100
xstart = 200
wordgap = 10
for i=1:size(teststr,1)
str=teststr{i};
wordlist = strsplit(str , ' ');
for j=1:size(wordlist)(1)
[nx, ny, textbounds]=DrawFormattedText(win, wordlist{j} ,xstart, ystart);
poslist{j} = textbounds;
xstart=nx+wordgap;
end
end
Not pretty, but it works. You will get problems if you have linebreaks.
EDIT: 2015-07-14: added wordgap suggestion from sven.io

Related

Roblox studio How do I change a TextLabel text in script

I want to make a gui that show your coordinates in game with text labels but my script seems didn't change the text at all
players = game.Players.LocalPlayer
players.CharacterAdded:Wait()
X = math.floor(players.Character.HumanoidRootPart.Position.X)
Y = math.floor(players.Character.HumanoidRootPart.Position.Y)
Z = math.floor(players.Character.HumanoidRootPart.Position.Z)
text = script.Parent.Text
while true do
text = X..","..Y..","..Z
X = math.floor(players.Character.HumanoidRootPart.Position.X)
Y = math.floor(players.Character.HumanoidRootPart.Position.Y)
Z = math.floor(players.Character.HumanoidRootPart.Position.Z)
end
please help me
I wanted to change the text to XYZ position in string
but everytime i launch the game the text didnt change
and it still at default text in roblox ui text label
The simple answer to your question of how do I change a TextLabel text is you just set the Text property.
script.Parent.Text = "Hello World"
If you want a simple way to track the changing position of a player's character, I would recommend using the Changed signal on the Part. It will fire the connected function every time the property changes, and it allows you to avoid using an infinite while-loop.
local text = script.Parent
local player = game.Players.LocalPlayer
-- wait for the player's character to exist
if not player.Character then
player.CharacterAdded:Wait()
end
-- listen for changes to the player's position
local hrp = player.Character.HumanoidRootPart
hrp:GetPropertyChangedSignal("Position"):Connect(function()
local position = hrp.Position
local x, y, z = math.floor(position.X), math.floor(position.Y), math.floor(position.Z)
-- format the position, and display it in the TextLabel
local positionString = string.format("(%d, %d, %d)", x, y, z)
text.Text = positionString
end)
So I can see that you have made few mistakes here
Explanation:
First of all, players.CharacterAdded:Wait() doesn't always work and never works in studio. So instead of that, you should use players.Character:WaitForChild("HumanoidRootPart").
Second thing. By calling text = script.Parent.Text you were requesting the text inside of it (you were getting it as a string), so to simply fix that you have to use text = script.Parent and then when changing text you will have to use text.Text = "your text".
The next one is making your while loop infinite by using bool true. You can't make it like that or else the playar may experience lag or even script may crash. So I'd suggest to put this to something like wait(0.1).
And the last thing is that you should get X,Y,Z before putting it into the text or else it will be delayed.
And your final script should be looking like this:
players = game.Players.LocalPlayer
players.Character:WaitForChild("HumanoidRootPart")
X = math.floor(players.Character.HumanoidRootPart.Position.X)
Y = math.floor(players.Character.HumanoidRootPart.Position.Y)
Z = math.floor(players.Character.HumanoidRootPart.Position.Z)
text = script.Parent
while wait(0.1) do
X = math.floor(players.Character.HumanoidRootPart.Position.X)
Y = math.floor(players.Character.HumanoidRootPart.Position.Y)
Z = math.floor(players.Character.HumanoidRootPart.Position.Z)
text.Text = X..","..Y..","..Z
end
Keep scripting, nothing is easy without practice,
KubaDC

PineScript - Keep in labels in the future when based on a fixed event

Thanks to the PineCoders on Twitter for pointing me in this direction.
I'm tracking both a hard stop (based on an entry indicator) and trailing stop and would like to keep them aligned.
bar_index+5 works great for the trailing stop, but for the hard stop, it simply places it 5 bars after entry indicator.
I've tried factoring in ta.barssince and it seems to have no effect, presumably since it believes the indicator is bar_index or something... I'm at a loss.
Here's the code:
SLAlabelText = str.tostring(SLCalc, "#.##")
var SLALabel = label.new(x = bar_index, y = SLCalc, color = color.red, style = label.style_none, textcolor = color.white, text=SLAlabelText)
if longBoy and stopLossA
label.set_xy(SLALabel, x = bar_index+5, y = SLCalc)
label.set_text(SLALabel, SLAlabelText)
label.set_tooltip(SLALabel, "Stop Loss: " + SLAlabelText)
"longBoy" is the indicator's confirmed state.
Chart image. Apologies for the meme stock, it was the best example.

Multiple title lines with variable using latex in matlab

I want to create the following title in my graph in Matlab:
text1 = ['Miss Distance at $$t_{f}= $$ ' num2str(MAT_ArrayRTM{1,end}) 'm'];
text2 = ['Miss Distance at $$t_{f}= $$ ' num2str(MAT_ArrayRTM{2,end}) 'm'];
title({'Planar Trajectories of the Missile and the Target' ...
text1 ...
text2}, ...
'fontweight','bold','fontsize',14,'Interpreter','latex');
Basically it should look like 3 lines title where the 2nd and 3rd contain a variable from the simulation.
It works fine when text1 and text2 are just strings, but the moment I use variables I get no title.
How can I make it work?
Thank you.
It is usually a good idea to use sprintf for string formatting. In your case
titeText = sprintf(['Planar Trajectories of the Missile and the Target\n' ...
'Miss Distance at $$t_{f}=%.1f$$ m\n'...
'Miss Distance at $$t_{f}=%.1f$$ m'], ...
MAT_ArrayRTM{1,end}, MAT_ArrayRTM{2,end});
should do the job. %.1f here specifies a floating point number with 1 number after the decimal point.

how to make image tilt correction by user input in matlab

I am developing a semi user interface , in which I want to introduce a user input in which a popup window should come and asking that "do you want to tilt the image?" with yes or no option.
If I press yes again one window should open and ask me to put the required angle through which you want to rotate the figure. If I press no. program should proceed as before. I have tried like this but not working.
dlgTitle = 'Tilt correction?';
dlgQuestion = 'Do you wish to Tilt the image?';
choice = questdlg(dlgQuestion,dlgTitle,'Yes','No', 'Yes');
prompt={'Enter a value of \theta (in degrees)'};
name = 'Tilt correction';
defaultans = {'30'};
options.Interpreter = 'tex';
answer = inputdlg(prompt,name,[1 40],defaultans,options);
end
i am not sure if i am addressing the right problem, but if its "the proceed at no" issue you missed an "if"
dlgTitle = 'Tilt correction?';
dlgQuestion = 'Do you wish to Tilt the image?';
choice = questdlg(dlgQuestion,dlgTitle,'Yes','No', 'Yes');
if strcmp(choice,'Yes')
prompt={'Enter a value of \theta (in degrees)'};
name = 'Tilt correction';
defaultans = {'30'};
options.Interpreter = 'tex';
answer = inputdlg(prompt,name,[1 40],defaultans,options);
end
if you want to adress the [1,40] range as well you need an additional loop. but this should already work for just yes and no

adding annotations to pdf using perl

I'm using the perl module PDF::API2::Annotation to add annotations to my pdf files.
There is support to decide where the annot will be created using a rect. Something like this:
$annot->text( $text, -rect => [ 10, 10, 10, 10 ] );
which works fine, but I'm having problem to be accurate on where to put my annotations.
I know the lower left corner of the pdf is (0,0). Let's say i want to put an annotation exactly in the middle of the page, any idea how can i achieve that?
according to this https://www.leadtools.com/help/leadtools/v18/dh/to/leadtools.topics.pdf~pdf.topics.pdfcoordinatesystem.html
a pdf is divided to points, and each point is 1/72 inch. and a pdf size is so the middle should be
(306,396)
But thats not even close to the middle.
You can get the size of the page media box and then calculate the middle from that:
# get the mediabox
my ($llx, $lly, $urx, $ury) = $page->get_mediabox;
# print out the page coordinates
say "page mediabox: " . join ", ", $llx, $lly, $urx, $ury;
# output: 0, 0, 612, 792 for the strangely-shaped page I created
# calculate the midpoints
my $midx = $urx/2;
my $midy = $ury/2;
my $annot = $page->annotation;
# create an annotation 20 pts wide and high around the midpoint of the mediabox
$annot->text($text, -rect=>[$midx-10,$midy-10,$midx+10,$midy+10]);
As well as the media box, you can also get the page crop box, trim box, bleed box, and art box:
for my $box ('mediabox', 'cropbox', 'trimbox', 'artbox', 'bleedbox') {
my $get = "get_$box";
say "$box dimensions: " . join ", ", $page->$get;
}
These are usually all the same unless the document has been set up for professional printing with a bleed area, etc.