Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
corresponding element of an array

Subject: corresponding element of an array

From: dibyendu

Date: 6 Jul, 2012 07:01:08

Message: 1 of 2

I have a matrix

frameno vehid distance
2902 HMV_1510 436
2903 AUTO_1588 310
2903 HMV_1510 436
2904 AUTO_1587 310
2904 HMV_1510 436
2905 AUTO_1588 308
2905 HMV_1510 436
2906 AUTO_1587 308
2906 HMV_1510 436
2907 AUTO_1588 306
2907 HMV_1510 436
2908 AUTO_1587 306
2908 HMV_1510 436
2909 AUTO_1588 308

now i want to find out the vehicle corresponding to distance in between 302 and 303, next if the vehicle is not in between 302 and 303(col3) then required to separate them and also required to check that if a vehicle id repeated in between 302 to 303 then it should be removed. After that the vehicle which are not coming in this range, their nearest frame no to be detected and need to extrapolate them to in this range. and required to find what will be the frame no corresponding to this range.

Subject: corresponding element of an array

From: dpb

Date: 14 Jul, 2012 14:05:34

Message: 2 of 2

On 7/6/2012 2:01 AM, dibyendu wrote:
> I have a matrix
>
> frameno vehid distance
> 2902 HMV_1510 436
...
> 2908 AUTO_1587 306
> 2908 HMV_1510 436
> 2909 AUTO_1588 308
>
> now i want to find out the vehicle corresponding to distance in between
> 302 and 303, next if the vehicle is not in between 302 and 303(col3)
> then required to separate them and also required to check that if a
> vehicle id repeated in between 302 to 303 then it should be removed.
> After that the vehicle which are not coming in this range, their nearest
> frame no to be detected and need to extrapolate them to in this range.
> and required to find what will be the frame no corresponding to this range.

Well, the first question is easy--there aren't any. :)

 >> type 'vehic.dat'

frameno vehid distance
2902 HMV_1510 436
2903 AUTO_1588 310
2903 HMV_1510 436
2904 AUTO_1587 310
2904 HMV_1510 436
2905 AUTO_1588 308
2905 HMV_1510 436
2906 AUTO_1587 308
2906 HMV_1510 436
2907 AUTO_1588 306
2907 HMV_1510 436
2908 AUTO_1587 306
2908 HMV_1510 436
2909 AUTO_1588 308

 >> [f,v,d]=textread('vehic.dat','%f %s %f','headerline',1);
 >> vset=v(ismember(d,[308:310])) % choose something in set for demo
vset =
     'AUTO_1588'
     'AUTO_1587'
     'AUTO_1588'
     'AUTO_1587'
     'AUTO_1588'
 >> unique(vset)
ans =
     'AUTO_1587'
     'AUTO_1588'
 >>

Use textscan() now; textread() is deprecated but my version predates its
introduction so I can't use it here...

Example to select a group; I chose something that is in the dataset
presented to get a result obviously. Make your selection whatever it is
you wish.

After that, it's basic manipulation...for the
distance/interpolation/extrapolation issue,

doc interp1

BTW, don't forget

doc ismember % and friends and particularly the alternate return values

--

Tags for this Thread

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.

Contact us