Thread Subject: error

Subject: error

From: nonyt

Date: 21 Nov, 2008 18:23:01

Message: 1 of 5

is there any way to check if i have integer elements in a vector??
any help?????

Subject: error

From: Walter Roberson

Date: 21 Nov, 2008 19:17:19

Message: 2 of 5

nonyt wrote:
> is there any way to check if i have integer elements in a vector??

I presume this relates to your homework question you posted yesterday, in which
one of the requirements was that you had to check that the elements of the matrix
were integers.

The answer to your question is "No, not reliably". Matlab works with finite
precision, and as far as it is concerned, there is no discernible difference
between 4503599627370496.5 and 4503599627370496. In fact, as far as Matlab
is concerned, there is no discernible difference between
9007199254740992 and 9007199254740993 .

*If* you are willing to restrict the range of values that are to be
operated over, and willing to restrict the meaning of "integers"
then you could consider the test x == floor(x) .
Unfortunately for you, as is pretty common, your assignment was broken
in the form it was written, making a complete solution impossible.


--
.signature note: I am now avoiding replying to unclear or ambiguous postings.
Please review questions before posting them. Be specific. Use examples of what you mean,
of what you don't mean. Specify boundary conditions, and data classes and value
relationships -- what if we scrambled your data or used -Inf, NaN, or complex(rand,rand)?

Subject: error

From: Loren Shure

Date: 21 Nov, 2008 22:13:59

Message: 3 of 5

In article <gg6ua5$714$1@fred.mathworks.com>, mariaki16@hotmail.com
says...
> is there any way to check if i have integer elements in a vector??
> any help?????
>
>

Will the function fix help you?


--
Loren
http://blogs.mathworks.com/loren

Subject: error

From: nonyt

Date: 21 Nov, 2008 22:50:17

Message: 4 of 5

actualy this i want is to chech if the input is string or float to output an error

Subject: error

From: Walter Roberson

Date: 22 Nov, 2008 01:46:07

Message: 5 of 5

nonyt wrote:
> actualy this i want is to chech if the input is string or float to output an error

if ischar(TheArg) || isfloat(TheArg)
  error('Try again, buster!')
end


That's what you have asked for in this posting, but having read the homework question
yesterday, I don't think you'll be happy with this code... The problem revolves
around the definition of the word "integers".

>> isfloat(1+2+3)

ans =
   1

>> isfloat(false)

ans =

   0


--
.signature note: I am now avoiding replying to unclear or ambiguous postings.
Please review questions before posting them. Be specific. Use examples of what you mean,
of what you don't mean. Specify boundary conditions, and data classes and value
relationships -- what if we scrambled your data or used -Inf, NaN, or complex(rand,rand)?

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com