The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Access to float coordinates in a 3D matrix
Replies: 10   Last Post: Dec 3, 2012 5:16 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]

Posts: 9,850
Registered: 6/7/07
Re: Access to float coordinates in a 3D matrix
Posted: Dec 3, 2012 9:56 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On 12/3/2012 8:11 AM, Javier wrote:

>> > I use
>> > x = x0 + t*dx
>> > y = y0 + t*dy
>> > z = z0 + t*dz
>> > with t: 0:0.1:1, and d the direction vector.
>> > This is the value of the coordinate isn't it?
>> >


> This are the first values for x: x(1),x(2) and x(3): 3,54551732809566
> 3,63234837121917 3,71917941434267 3.
> They are floating points because I have a decimal resolution. If for
> example I want to acces Structures (x(1),y(1),z(1)), I can't.

Well, no, you can't. At the command line...from your values

>> t= 0:0.1:1;
>> d0=3.54551732809566;
>> dx=0.0868310431235;
>> x=d0+t*dx

x =
Columns 1 through 7
3.5455 3.5542 3.5629 3.5716 3.5802 3.5889 3.5976
Columns 8 through 11
3.6063 3.6150 3.6237 3.6323

Note that x is a row vector of 10 elements. You can't have indices that
aren't integers--what would the entry in x be? The question
makes no sense posed that way.

What, specifically, are you trying to do that you're trying to write
x(a_x_value) instead of x(an_index_value)?

If you're trying to locate where within the array a particular value is
located, you can use find() or logical addressing (subject to the
caveats that equality-testing for floating point is subject to precision
problems so that you may not find the result if do exact comparisons).

At the command line again...

>> ix=find(t==0.3)
ix =

Note above returned []...what's up w/ that? Let's see...

>> t(4)-0.3
ans =

Ah, note the small discrepancy between the value of approximately 0.3
that you obtained from the floating point construction used to build the
t vector and that which was converted to internal representation when
typed in '0.3' at the command line...this is normal and one has to be
sure to deal with it when using floating point.

So, let's try something else...

>> ix=find(abs(t-0.3)<1E-6)
ix =
>> x(ix)
ans =

Hopefully that will clarify the problem you're having. The lesson to
learn is

A) There _can't_ be anything but an integer array index

B) Floating point comparisons aren't exact

Again, clarify what you're _really_ trying to do that causes you to
write what you've written...


Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.