# Matlab window example broken

**URL:** https://mworks.discourse.group/t/matlab-window-example-broken/571
**Category:** Support
**Created:** [July 16, 2014, 6:33pm UTC](https://mworks.discourse.group/t/matlab-window-example-broken/571 "2014-07-16T18:33:05Z")
**Posts on this page:** 3
**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 16, 2014, 6:33pm UTC](https://mworks.discourse.group/t/matlab-window-example-broken/571/1 "2014-07-16T18:33:05Z")

</div>

This is minor. I was just doing the Matlab window tutorial and got the following error:

> > Error: Integers can only be combined with integers of the same class, or scalar doubles. (MATLAB:mixedClasses)  
> > In linspace.m at 30  
> > In hist.m at 94  
> > In matlab\_window\_demo.m at 22

I figured out there are two reasons for this error: First, MWorks is making rand\_var an int64 (or that’s how Matlab is seeing it at least). This still happens even if I define rand\_var as an integer. I have to use MWorks’ rand() if I want Matlab to get doubles. This is a problem because the default bin centers for Matlab’s hist() aren’t integers, which causes the error. However, setting the bin centers to integers (1:10), I get a different error:

> > Error: First Input type not supported (MATLAB:histc:InvalidFirstNumericInput)  
> > In hist.m at 119  
> > In matlab\_window\_demo.m at 22

Apparently hist() doesn’t like int64 objects at all. So there are two solutions, ignoring the option of changing disc\_rand() to rand() in the .xml file:

1. Have the m-file recast to a double or an integer type that the function you want to use likes.
2. Figure out a way to get MWorks to output a variable as a double even if the values are all (mathematically) integers.

I have no idea how difficult it would be to do #2, and it might break current functionality, so I’m guessing #1 is the better of the two.

---

<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:56pm UTC](https://mworks.discourse.group/t/matlab-window-example-broken/571/2 "2014-07-17T19:56:37Z")

</div>

Hi Evan,

Thanks for reporting this. I made the change that introduced this issue quite a while ago, but I failed to update the tutorial.

Luckily, this problem is easy to fix. To fix it in the .m file, replace

```
hist(values);

```

with

```
hist(cast(values, 'double'));

```

To fix it in the .xml file, replace

```
disc_rand(1, 10)

```

with

```
(double)disc_rand(1, 10)

```

I prefer and recommend the first option, so I’ve posted an updated version of the .m file 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 19, 2022, 10:58pm UTC](https://mworks.discourse.group/t/matlab-window-example-broken/571/3 "2022-07-19T22:58:28Z")

</div>


