dpb
Posts:
9,840
Registered:
6/7/07


Re: Access to float coordinates in a 3D matrix
Posted:
Dec 3, 2012 9:56 AM


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 integerswhat would the 3.5542...th 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 equalitytesting 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 = 5.5511e017
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(t0.3)<1E6) ix = 4 >> x(ix) ans = 3.5716 >>
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...


