rounding excel columns with Matlab

4 views (last 30 days)
Hexus
Hexus on 18 Apr 2012
I need to write a code that can round any number to any required digit from an excel document. Basically, in the excel document, if you find 10 in the second column, then round the value of the first column to the nearest 10. If you find 0.001 in the second column,then round the value of the first column to the nearest 0.001
The problem is, is that I'm not allowed to use any built in functions. (such as round, ceil, floor, fix, max, min, find, etc...) I'm ONLY allowed to use length, size, relationship operators {<> ~ =}, logical operators ({I,&}, if, for, while, switch.
  1 Comment
Image Analyst
Image Analyst on 18 Apr 2012
http://www.mathworks.com/matlabcentral/answers/8626-how-do-i-get-help-on-homework-questions-on-matlab-answers

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 18 Apr 2012
It is not possible to do that operation with those restrictions.
  • those operations are not able to read an excel document
  • you need to use arithmetic operations to do the rounding. Even the Peano Postulates require the operation of adding 1.
  • it is not actually possible to round binary numbers to multiples of .1 or .01 or .001 etc.
  2 Comments
Hexus
Hexus on 18 Apr 2012
I apologize. I should have presented the question better. I'm not actually looking for Matlab to read the values from the excel document. What I'm trying to do is have excel read any possible array and round the values to any digit I choose.
Is it possible to write a code with these constraints that will round arrays element by element within matlab, then maybe implement xlswrite to execute the commands in excel?
Walter Roberson
Walter Roberson on 18 Apr 2012
xlswrite() cannot execute commands in excel: it can only write cells, not execute anything.
MATLAB cannot execute commands in excel without use of actxserver() which is not on your list of allowed functions. Also, actxserver() is only supported in MS Windows.
It is not possible to do the rounding using the list of allowed functions you indicate -- not with any program that would fit within the maximum memory that can be allocated in MATLAB (2^48 bytes). More than 2^67 bytes of code would be required to do the rounding with only the functions on your allowed function list.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!