MatLab: Div function?

This topic is 2080 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

First of all, I hope I posted in the right forum section.

Is there a Div function in MatLab?

For example:  the div of 15/4 = 3??

I tried: 15 div 4

and i get an Error: Unexpected MATLAB expression.

I have been searching all over internet without finding anything...

I use the 2011 version.

Share on other sites

Divide and round the result. Depending on how you want to round negative numbers, you have the option to use floor or fix.

Share on other sites

I know that it works by just making the  division then using floor.

But was wondering if there was a function. :P

Share on other sites

Never used MatLab. I have used google before though...

http://www.mathworks.co.uk/help/matlab/ref/idivide.html

It looks like

a ./ b

will work.

I googled "matlab integer division function"

EDIT: Maybe not, as I said I haven't used MatLab before... EDIT2: That looks like some kind of array operator, so go with idivide

Share on other sites

I just tried it does not work. :)

Anyways I created a div function myself for now. :P

Share on other sites

Yeah I realised it wasn't right and edited, looks like idivide is what you want. I can't do a search for ./ using the search box and it's not hyperlinked... not impressed with the MatLab documentation!

Share on other sites

First of all, I hope I posted in the right forum section.

Is there a Div function in MatLab?

For example:  the div of 15/4 = 3??

I tried: 15 div 4

and i get an Error: Unexpected MATLAB expression.

I have been searching all over internet without finding anything...

I use the 2011 version.

There is this,

http://www.mathworks.com/help/matlab/ref/idivide.html

-Josh

Share on other sites

idivide is probably the function you want. FYI, you can also cast matrices to integers using int32() and other primitive types.

• 11
• 9
• 17
• 13
• 11