'for' loop with rectangles

Hi all,
Sorry for the very naïve question, I hope one of you could help,
maybe there's a very simple solution to my problem.
I need to run a very simple `for' loop:

for n=2:70;
topleftx(n)=(topleftx(n-1))+
((largeurfixloc*0.028039052+(((topleftx(n-1))-topleftx(1))
*0.028039052)*0.046)*35.66454331)/2;
largeur(n)=(largeurfixloc*0.028039052+(((topleftx(n-
1))-topleftx1)*0.028039052)*0.046)*35.66454331;
hauteur(n)=largeur(n)*1.354166666;
toplefty(n)=toplefty(1)-((hauteur(n)-hauteurfixloc)/2);
bottomrightx(n)=topleftx(n)+largeur(n);
bottomrighty(n)=toplefty(n)+hauteur(n);
targn=SetRect(topleftx(n),toplefty(n),bottomrightx
(n),bottomrighty(n));
Screen('DrawTexture', w, texturetot ,kar(n) ,targ(n),
0);
end;

Of course it doesn't work (it's why I write this mail). It seems to
be because of kar(n) and targ(n). Indeed kar(n) are 1 line matrices
of the form kar(1)= SetRect(960,100,1008,165) for instance and
SetRect(left,top,right,bottom) is equivalent to
[left,top,right,bottom].
I've got the same problem with targ(n), these ones being some
rectangles too.
And if I understood a bit, the fact to specify a(1)=10, a(2)=20
creates a matrix a=[10, 20], so kar would be a matrix of matrices
and apparently matlab doesn't like that.
I thought to use a structure for kar but kar.n (I mean kar.'number')
is not accepted. So I'm quite stuck. Please tell me I'm very stupid
and there's a simple solution.

For the context, I need to display very quickly some letters but
the `drawtext' function is too slow (not by itself but because I
need to change the size for each letter it takes 8secs for 50
characters, not ideal for a gaze contingent paradigm). `Putimage' is
also too slow so I use a texture with all letters and I define some
rectangles for each letter then I draw the wanted rectangles in some
target rectangles of size and at the position I need.

Thanks a lot if I can help and even if you can't :)
seb
Hi Seb,

i don't 100% figured out what u really want to do (to less sleep last night ^.^).
Am i right, that you have a image where some letters are stored?
for example:

letter=imread('myletters.gif');
and you want some parts of this image to be shown somewhere on the screen?

In this case, you have to firstly make a Texture via Screen('MakeTexture'..):

TextureIndex=Screen('MakeTexture',w,letter);

Then you can draw your texture like this:

Screen('DrawTexture',w,TextureIndex,sourceRect,destinationRect);

where sourceRect is the part of your image (4 values: the first two for the upper left corner
of the rectangle, and second two for the lower right corner........remember that 0,0 is at
the upper left in matlab, so [1 1 20 20] would be a 20x20 square at the upper legt
corner)
and destinationRect is where you want to draw this rect (4 values too).

Screen('Flip',w);

Hopefully this may help you

cheers

florian

--- In psychtoolbox@yahoogroups.com, "s.miellet" <s.miellet@...> wrote:
>
> Hi all,
> Sorry for the very naïve question, I hope one of you could help,
> maybe there's a very simple solution to my problem.
> I need to run a very simple `for' loop:
>
> for n=2:70;
> topleftx(n)=(topleftx(n-1))+
> ((largeurfixloc*0.028039052+(((topleftx(n-1))-topleftx(1))
> *0.028039052)*0.046)*35.66454331)/2;
> largeur(n)=(largeurfixloc*0.028039052+(((topleftx(n-
> 1))-topleftx1)*0.028039052)*0.046)*35.66454331;
> hauteur(n)=largeur(n)*1.354166666;
> toplefty(n)=toplefty(1)-((hauteur(n)-hauteurfixloc)/2);
> bottomrightx(n)=topleftx(n)+largeur(n);
> bottomrighty(n)=toplefty(n)+hauteur(n);
> targn=SetRect(topleftx(n),toplefty(n),bottomrightx
> (n),bottomrighty(n));
> Screen('DrawTexture', w, texturetot ,kar(n) ,targ(n),
> 0);
> end;
>
> Of course it doesn't work (it's why I write this mail). It seems to
> be because of kar(n) and targ(n). Indeed kar(n) are 1 line matrices
> of the form kar(1)= SetRect(960,100,1008,165) for instance and
> SetRect(left,top,right,bottom) is equivalent to
> [left,top,right,bottom].
> I've got the same problem with targ(n), these ones being some
> rectangles too.
> And if I understood a bit, the fact to specify a(1)=10, a(2)=20
> creates a matrix a=[10, 20], so kar would be a matrix of matrices
> and apparently matlab doesn't like that.
> I thought to use a structure for kar but kar.n (I mean kar.'number')
> is not accepted. So I'm quite stuck. Please tell me I'm very stupid
> and there's a simple solution.
>
> For the context, I need to display very quickly some letters but
> the `drawtext' function is too slow (not by itself but because I
> need to change the size for each letter it takes 8secs for 50
> characters, not ideal for a gaze contingent paradigm). `Putimage' is
> also too slow so I use a texture with all letters and I define some
> rectangles for each letter then I draw the wanted rectangles in some
> target rectangles of size and at the position I need.
>
> Thanks a lot if I can help and even if you can't :)
> seb
>
If you want to have multiple letter drawn at one time you probably has
to try something like this:

Word='HansDieter';
Lettersize=20; % every letter has his one surrounding square
of 20 x 20 Pixels

for i=1:size(Word,2)

tmp(1:Lettersize;i*Lettersize:i*Lettersize+Lettersize)=findLetter(Word,i,Letter);

% would built a 2 dimensional array, where findLetter returns you the
single letters out of the Letters-Image
%after that tmp is a [20,80]-array which you can use for the make and
draw-texture


Let me know if this is, what you are looking for