# Matlab window issue

**URL:** <https://mworks.discourse.group/t/matlab-window-issue/552>\
**Category:** Support\
**Created:** [July 17, 2014, 7:15pm UTC](https://mworks.discourse.group/t/matlab-window-issue/552 "2014-07-17T19:15:42Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [July 17, 2014, 7:15pm UTC](https://mworks.discourse.group/t/matlab-window-issue/552/1 "2014-07-17T19:15:42Z")

</div>

Hi Chris,

I’m learning how to use the Matlab window. One small question, and a problem:

- What does “process {x} events” mean? Why is it 0 sometimes, and 1 other times?

- I’ve written an m-file that plots some data every time it’s called. From your example, the way this gets called is that “sync” is set from 1 to 0. My MWorks program cycles through blocks of trials, setting sync = 1 at the start of the block, 0 at the end, then back to 1 immediately. The data from the first block gets plotted, but not for successive blocks. Stopping and starting the program doesn’t fix the problem. In fact, if I try to unload the program after the m-file has been called, the client stops responding and I have to force quit. Would you mind helping me figure out what’s going wrong?

Thanks,  
Evan

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [July 17, 2014, 7:37pm UTC](https://mworks.discourse.group/t/matlab-window-issue/552/2 "2014-07-17T19:37:16Z")

</div>

Hi Evan,

> What does “process {x} events” mean? Why is it 0 sometimes, and 1 other times?

If “Collecting Data” is checked but “Process X events” is not, then the MATLAB bridge will collect the selected events but will _not_ invoke your script. If you subsequently check “Process events”, the collected events will be sent to your script at that time.

> The data from the first block gets plotted, but not for successive blocks. Stopping and starting the program doesn’t fix the problem. In fact, if I try to unload the program after the m-file has been called, the client stops responding and I have to force quit.

I think this is a bug. I see it with MATLAB R2014a, but not with R2011a. Let me dig in a little further and see what’s going on.

Thanks,  
Chris

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [July 18, 2014, 2:07pm UTC](https://mworks.discourse.group/t/matlab-window-issue/552/3 "2014-07-18T14:07:21Z")

</div>

Hi Evan,

It looks like the client freeze is related to [this issue](https://mworks.discourse.group/discussions/problems/115). It appears that under MATLAB R2014a, the MATLAB engine API (specifically the [engGetVariable](http://www.mathworks.com/help/matlab/apiref/enggetvariable.html) function) gets stuck when the variable value is an int64 array. The only feedback we get is a rather unhelpful message sent to the console:

```
{Error using save
Can't write file stdio.
} 
Error writing to output stream.

```

I assume this is a bug, not a design choice.

The fix is to ensure that your MATLAB script returns a double array. I’ve attached an updated matlab\_window\_demo.m and will also post it to the tutorial.

Cheers,  
Chris

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [July 18, 2014, 2:07pm UTC](https://mworks.discourse.group/t/matlab-window-issue/552/4 "2014-07-18T14:07:21Z")

</div>

Attachment: [matlab\_window\_demo.m](https://mworks.discourse.group/uploads/short-url/pIUaSrqUGdBZo1dct3GqHCX2sUG.m) (499 Bytes)

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [July 18, 2014, 5:33pm UTC](https://mworks.discourse.group/t/matlab-window-issue/552/5 "2014-07-18T17:33:17Z")

</div>

Hi Chris,

Thanks for figuring that out. I was using a struct (of doubles), but either way using the double array fixed the problem. I guess it would be nice to be able to use other data types (like structs), but this works so that would be a low priority item if anything. Maybe it would help to submit a bug report to Mathworks?

Also, how did you know the problem was in the return value from the matlab script? Just that console message?

- Evan

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [July 18, 2014, 8:10pm UTC](https://mworks.discourse.group/t/matlab-window-issue/552/6 "2014-07-18T20:10:55Z")

</div>

> Maybe it would help to submit a bug report to Mathworks?

Yeah, that’s probably a good idea.

> Also, how did you know the problem was in the return value from the matlab script? Just that console message?

I ran MWClient in the Xcode debugger and saw that it (1) hung at engGetVariable and (2) produced that console message. Feeding the console message in to Google led me to [this thread](http://www.mathworks.com/matlabcentral/newsreader/view_thread/335923), which suggested that the data type of the variable was the problem.

Actually, I fully expected this to be an MWorks bug, so I was both pleased and surprised to discover that it wasn’t.

Chris

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [September 18, 2014, 12:28pm UTC](https://mworks.discourse.group/t/matlab-window-issue/552/7 "2014-09-18T12:28:38Z")

</div>

Just an update - I finally submitted a ticket to Matlab about adding support for other data types in the engGetVariable function.

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [September 22, 2014, 1:09am UTC](https://mworks.discourse.group/t/matlab-window-issue/552/8 "2014-09-22T01:09:16Z")

</div>

Hi Chris,

I heard back from The Mathworks. They passed along an example program. From the rep:

> I have created a sample C program file ‘demo.c’ which demonstrates the usage of ‘engGetVariable’ method to get the ‘struct’ and ‘cell array’ data structures from that MATLAB environment to the C environment. I have also added the appropriate comments wherever necessary inside the code.

> In order to compile demo.c program, please use following command at MATLAB command line:

> `mex -client engine demo.c`

> This will generate an ‘exe’ file. Please execute this file using windows command prompt to see the output of ‘printf’ statements inside the code.

I don’t have anything waiting on this functionality. Just wanted to add the update.

Evan

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [September 22, 2014, 1:09am UTC](https://mworks.discourse.group/t/matlab-window-issue/552/9 "2014-09-22T01:09:16Z")

</div>

Attachment: [demo.c](https://mworks.discourse.group/uploads/short-url/aS0DMM54kwZDFsLoLKj17lTAFER.c) (1.94 KB)

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [September 24, 2014, 3:01pm UTC](https://mworks.discourse.group/t/matlab-window-issue/552/10 "2014-09-24T15:01:25Z")

</div>

Hi Evan,

The example program demonstrates the same bug:

```
>> mex -client engine demo.c  
Building with 'Xcode with Clang'.
MEX completed successfully.
>> quit
$ DYLD_LIBRARY_PATH=/Applications/MATLAB_R2014a.app/bin/maci64 ./demo 

 Creating structure 'sampleStructure' 

 Retrieving structure 'sampleStructure'
Error using save
Can't write file stdio.

```

And there it hangs.

It sounds like the MathWorks guy tested his example on Windows. Maybe you should tell him to try it on a Mac.

Thanks,  
Chris

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [September 25, 2014, 8:00pm UTC](https://mworks.discourse.group/t/matlab-window-issue/552/11 "2014-09-25T20:00:31Z")

</div>

Relaying from Mathworks:

> I tried to run ‘demo.c’ program on Mac operating system. I was successfully able to \>run it on Mac OS X 10.9.2 from system terminal. Following are the steps which I \>followed for compiling and running this program:
> 
> 1. At the beginning, I made sure that the ‘PATH’ environment variable includes /bin  
> path.  
> If it is not present in your case, then you can use the following command to include that path:  
> setenv PATH ‘/bin’:$PATH
> 
> 2. I then executed following commands in order to set the environment variable  
> ‘DYLD\_LIBRARY\_PATH’ properly.
> 
> 3. I compiled demo.c program from MATLAB command line using following command:  
> mex -client engine demo.c

> 1. I ran demo program from the same system terminal as below

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [September 26, 2014, 2:36pm UTC](https://mworks.discourse.group/t/matlab-window-issue/552/12 "2014-09-26T14:36:52Z")

</div>

Hi Evan,

I still see the bug:

```
$ PATH=/Applications/MATLAB_R2014a.app/bin:$PATH DYLD_LIBRARY_PATH=/Applications/MATLAB_R2014a.app/bin/maci64:/Applications/MATLAB_R2014a.app/sys/os/maci64 ./demo

 Creating structure 'sampleStructure' 

 Retrieving structure 'sampleStructure'
Error using save
Can't write file stdio.

```

I tried it on two machines, one running OS X 10.9.5, the other 10.8.5, and I got the same result both times.

If there a way for me to get in touch with this person directly? Or should I just open another bug report?

Thanks,  
Chris

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [September 27, 2014, 12:39pm UTC](https://mworks.discourse.group/t/matlab-window-issue/552/13 "2014-09-27T12:39:11Z")

</div>

Hi Chris,

Apparently this bug is specific to Mac/2014a, and will be fixed in the 2014b release. Not sure why Mathworks didn’t catch that initially; the OS/release version was included in my original service request. Sorry about the time waste on this.

- Evan

---

<div class="post-metadata">

**Author:** ![cstawarz](https://yyz1.discourse-cdn.com/flex031/user_avatar/mworks.discourse.group/cstawarz/32/3_2.png) [@cstawarz](https://mworks.discourse.group/u/cstawarz)\
**Post date:** [July 19, 2022, 10:57pm UTC](https://mworks.discourse.group/t/matlab-window-issue/552/14 "2022-07-19T22:57:08Z")

</div>


