FW: Polhemus

278 views
Skip to first unread message

Cognitology

unread,
May 7, 2013, 10:08:28 AM5/7/13
to e-p...@googlegroups.com

Hi,

Never heard of a way to interface matlab from E-Prime, I’d be interested if anyone would have a way. Of course, you could compile from within matlab and try to go from there, but I suspect the amount of effort would really not be worth it. You could, of course, just forego e-prime and try Psychtoolbox.

Best,

Michiel

 

From: e-p...@googlegroups.com [mailto:e-p...@googlegroups.com] On Behalf Of Tobias
Sent: 7. May 2013 13:31
To: e-p...@googlegroups.com
Subject: Re: Polhemus

 

To be more precisely: What I need to do is to start a matlab script from E-Prime.
"Presentation" has some plugin to connect with Matlab, but E-Prime seems not to have that. But there may be another way...

Am Montag, 6. Mai 2013 15:39:19 UTC+2 schrieb Tobias:

Dear all,

Does anyone have experience with running Polhemus Liberty (the motion tracking system) with E-Prime?

Best,
Tobias

--
You received this message because you are subscribed to the Google Groups "E-Prime" group.
To unsubscribe from this group and stop receiving emails from it, send an email to e-prime+u...@googlegroups.com.
To post to this group, send email to e-p...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/e-prime/-/GxclTVJPyVEJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

David McFarlane

unread,
May 7, 2013, 10:26:08 AM5/7/13
to e-p...@googlegroups.com
Can you start your MATLAB script from a command line? If so, then
you might try using the E-Basic "Shell()" function, see that topic in
the E-Basic Help facility. For a user example of this, see
http://support.pstnet.com/forum/Topic1338-8-2.aspx . This still
leaves a lot to be desired, and beyond that I have no idea.

-----
David McFarlane
E-Prime training
online: http://psychology.msu.edu/Workshops_Courses/eprime.aspx
Twitter: @EPrimeMaster (https://twitter.com/EPrimeMaster)

/----
Stock reminder: 1) I do not work for PST. 2) PST's trained staff
take any and all questions at
http://support.pstnet.com/e%2Dprime/support/login.asp , and they
strive to respond to all requests in 24-48 hours, so make full use of
it. 3) In addition, PST offers several instructional videos on their
YouTube channel (http://www.youtube.com/user/PSTNET ). 4) If you do
get an answer from PST staff, please extend the courtesy of posting
their reply back here for the sake of others.
\----


At 5/7/2013 10:08 AM Tuesday, Cognitology wrote:
>Hi,
>Never heard of a way to interface matlab from E-Prime, I'd be
>interested if anyone would have a way. Of course, you could compile
>from within matlab and try to go from there, but I suspect the
>amount of effort would really not be worth it. You could, of course,
>just forego e-prime and try Psychtoolbox.
>Best,
>Michiel
>

Paul Groot

unread,
May 7, 2013, 11:01:32 AM5/7/13
to e-p...@googlegroups.com
I don't think eprime requires a special plugin like presentation, because matlab can also be started as a so called COM server:

Dim MatLab As Object
Dim Result As String
Dim MReal(1, 3) As Double
Dim MImag(1, 3) As Double

Set MatLab = CreateObject("Matlab.Application")

'Executing other MATLAB commands
Result = MatLab.Execute("surf(peaks)")
Debug.Print Result

Result = MatLab.Execute("a = [1 2 3 4; 5 6 7 8]")
Debug.Print Result

Result = MatLab.Execute("b = a + a ")
Debug.Print Result

'Bring matrix b into VB program
MatLab.GetFullMatrix "b", "base", MReal, MImag

Debug.Print MReal(1,0)
Debug.Print MReal(1,1)
Debug.Print MReal(1,2)
Debug.Print MReal(1,3)



The above will print the following to the Debug window:

a =

     1     2     3     4
     5     6     7     8



b =

     2     4     6     8
    10    12    14    16


10
12
14
16

The matlab figure window won't be visible though...

Best,
Paul



On 7 May 2013 16:26, David McFarlane <mcfa...@msu.edu> wrote:
Can you start your MATLAB script from a command line?  If so, then you might try using the E-Basic "Shell()" function, see that topic in the E-Basic Help facility.  For a user example of this, see http://support.pstnet.com/forum/Topic1338-8-2.aspx .  This still leaves a lot to be desired, and beyond that I have no idea.

-----
David McFarlane
E-Prime training online:  http://psychology.msu.edu/Workshops_Courses/eprime.aspx
Twitter:  @EPrimeMaster (https://twitter.com/EPrimeMaster)

/----
Stock reminder:  1) I do not work for PST.  2) PST's trained staff take any and all questions at http://support.pstnet.com/e%2Dprime/support/login.asp , and they strive to respond to all requests in 24-48 hours, so make full use of it.  3) In addition, PST offers several instructional videos on their YouTube channel (http://www.youtube.com/user/PSTNET ).  4) If you do get an answer from PST staff, please extend the courtesy of posting their reply back here for the sake of others.
\----



At 5/7/2013 10:08 AM Tuesday, Cognitology wrote:
Hi,
Never heard of a way to interface matlab from E-Prime, I'd be interested if anyone would have a way. Of course, you could compile from within matlab and try to go from there, but I suspect the amount of effort would really not be worth it. You could, of course, just forego e-prime and try Psychtoolbox.
Best,
Michiel

From: <mailto:e-prime@googlegroups.com>e-p...@googlegroups.com [mailto:e-prime@googlegroups.com] On Behalf Of Tobias

Sent: 7. May 2013 13:31

Subject: Re: Polhemus

To be more precisely: What I need to do is to start a matlab script from E-Prime.
"Presentation" has some plugin to connect with Matlab, but E-Prime seems not to have that. But there may be another way...

Am Montag, 6. Mai 2013 15:39:19 UTC+2 schrieb Tobias:
Dear all,

Does anyone have experience with running Polhemus Liberty (the motion tracking system) with E-Prime?

Best,
Tobias
--
You received this message because you are subscribed to the Google Groups "E-Prime" group.
To unsubscribe from this group and stop receiving emails from it, send an email to e-prime+unsubscribe@googlegroups.com.

To post to this group, send email to e-p...@googlegroups.com.

Tobias

unread,
May 9, 2013, 3:47:22 PM5/9/13
to e-p...@googlegroups.com
Thanks for your postings!

I tried with the shell function first because that seems to be the easiest way. To begin with I just wanted to try starting matlab from within E-Prime, without any matlab script.

I used this E-Prime script:

Dim snd as String
Dim MyAppID As String
snd = "C:\Program Files\MATLAB\R2012a\bin\matlab.exe"
MyAppID = Shell(snd)

... and the following error message occured:
"The following runtume error occurred: Device I/O error, Line:205; Error Number 57"

So I had a closer look at the link you posted (by this Matthias guy) and thought maybe I need to pause E-Prime. So I used this code:

"Dim snd as String
Dim MyAppID As String
Rte.DeviceManager.Suspend
snd = "C:\Program Files\MATLAB\R2012a\bin\matlab.exe"
MyAppID = Shell(snd,0) 'use 0 instead of 1 hide the wmp
sleep(10000)"

However, same error message :-(

According to the interwebs, this error message has to do with external devices. But I don't use any. Puzzling!
Do you have any script for E-Prime that just starts some program, whatever it may be?

Thanks a lot,
Tobias
Rte.DeviceManager.Resume

David McFarlane

unread,
May 9, 2013, 4:06:50 PM5/9/13
to e-p...@googlegroups.com
Tobias,

The "AppActivate" topic in the E-Basic Help facility contains a
complete code example. I went ahead and pasted the complete example
into good-old EP1 E-Run to test it out myself. Sadly, it does not
work. First, it fails to declare its "id" variable. Fixing that got
me to a "Path/File access error". Substituting "notepad.exe" for
"clock.exe" then got me to a "Can't find window" error on the
AppActivate line. Using the id variable instead of a window name
string there got me to a "Can't find window" error on the AppClose
line. Once again using the id variable instead of a window name
string got me a fully working example. So here is the fully working result:

Sub Main()
dim id
id = Shell("notepad.exe",1)
AppActivate id
Sleep(2000)
AppClose id
End Sub

Of course, to test this in an E-Studio inline object (instead of EP1
E-Run), you need to leave out the first and last lines (Sub Main(), End Sub).

And that is everything I know about this business :).

-----
David McFarlane
E-Prime training
online: http://psychology.msu.edu/Workshops_Courses/eprime.aspx
Twitter: @EPrimeMaster (https://twitter.com/EPrimeMaster)


><http://support.pstnet.com/forum/Topic1338-8-2.aspx>http://support.pstnet.com/forum/Topic1338-8-2.aspx
>. This still
>leaves a lot to be desired, and beyond that I have no idea.
>
>-----
>David McFarlane
>E-Prime training
>online:
><http://psychology.msu.edu/Workshops_Courses/eprime.aspx>http://psychology.msu.edu/Workshops_Courses/eprime.aspx
>
>Twitter: @EPrimeMaster
>(<https://twitter.com/EPrimeMaster>https://twitter.com/EPrimeMaster)
>
>/----
>Stock reminder: 1) I do not work for PST. 2) PST's trained staff
>take any and all questions at
><http://support.pstnet.com/e%2Dprime/support/login.asp>http://support.pstnet.com/e%2Dprime/support/login.asp
>, and they
>strive to respond to all requests in 24-48 hours, so make full use of
>it. 3) In addition, PST offers several instructional videos on their
>YouTube channel
>(<http://www.youtube.com/user/PSTNET>http://www.youtube.com/user/PSTNET

Tobias

unread,
May 12, 2013, 10:16:05 AM5/12/13
to e-p...@googlegroups.com
David,

thanks for your suggestion. I used your code and it worked fine. However, the code does not work with matlab. The same error you had earlier ("Can't find window") appears. Nevertheless, Matlab starts and even executes a script if I am using sth like "id = Shell("matlab -r script.m",1) ". So in principle it works but of course I don't want to have this error message since that interrupts the whole program.

Do you have any idea how to work around this window error problem?

Best,
Tobias

Tobias

unread,
May 13, 2013, 6:19:21 AM5/13/13
to e-p...@googlegroups.com
Dear Paul,

thanks a lot for this code. It works very well. There are some issued I have, though.

From your script I understand that there are at least two ways of getting data from Matlab to E-Prime: Execute and getfullmatrix. Are there other ways?
Also, it seems that there is no way of transmitting a variable from E-Prime to Matlab, only string values such as "b = a + a".
Of course I could always use sth like

Result = MatLab.Execute(CStr(eprimeVar))

If I wanted to get the variable eprimeVar from E-Prime to Matlab. But maybe there is an easier way?

Best,
Tobias



From: <mailto:e-p...@googlegroups.com>e-p...@googlegroups.com [mailto:e-p...@googlegroups.com] On Behalf Of Tobias

Sent: 7. May 2013 13:31

Subject: Re: Polhemus

To be more precisely: What I need to do is to start a matlab script from E-Prime.
"Presentation" has some plugin to connect with Matlab, but E-Prime seems not to have that. But there may be another way...

Am Montag, 6. Mai 2013 15:39:19 UTC+2 schrieb Tobias:
Dear all,

Does anyone have experience with running Polhemus Liberty (the motion tracking system) with E-Prime?

Best,
Tobias

--
You received this message because you are subscribed to the Google Groups "E-Prime" group.
To unsubscribe from this group and stop receiving emails from it, send an email to e-prime+u...@googlegroups.com.

To post to this group, send email to e-p...@googlegroups.com.

Paul Groot

unread,
May 13, 2013, 12:23:54 PM5/13/13
to e-p...@googlegroups.com
Hi Tobias,

More detailed information about matlab's COM interface can be found here:
http://www.mathworks.nl/help/matlab/call-matlab-com-automation-server.html

There are a few functions available to pass variables, character array's, matrices and workspaces between the two applications, without the need to convert strings. The execute command should be used to execute scripts; not for passing variables (although you can do this off course). Large objects (like bitmap images) could also be passed by using external files (i.e. only passing the name of the created file).

Best
Paul



To view this discussion on the web visit https://groups.google.com/d/msg/e-prime/-/kIUzT6nN__AJ.

Tobias

unread,
May 25, 2013, 1:53:47 PM5/25/13
to e-p...@googlegroups.com
Thanks for all the help.

I have successfully implemented Polhemus in E-Prime.

There is only one problem left: When a lot of data is recorded, which is not unusual for longer movements of particpants, the string becomes too long for E-Prime.

I use this function:

x = MatLab.Execute("dataCapture;")

For longer recordings which makes data rather large the following error occurs:
"Error number 14: Out of string space"

The thing is, I don't really need any of the recorded data for E-Prime. But I can't find a way to not have E-Prime import the data into the variable x.
Is there a way of executing MatLab function without forwarding data to Matlab?

Best,
Tobias

Paul Groot

unread,
May 25, 2013, 4:35:31 PM5/25/13
to e-p...@googlegroups.com
I don't know anything about polhemus or the datacapture function, but it sounds like this function generates a lot of output in the matlab command window. You can capature this into a dummy variable by using evalc:

x = MatLab.Execute("dummy=evalc('dataCapture;');")


Mind the single and double quotes)

best
Paul


Tobias

unread,
May 27, 2013, 11:32:26 AM5/27/13
to e-p...@googlegroups.com
That worked! Great, thanks!
Reply all
Reply to author
Forward
0 new messages