Got Questions? Get Answers.
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:
Two vectors different dimensions

Subject: Two vectors different dimensions

From: Aaron Anstey

Date: 7 Sep, 2010 20:15:06

Message: 1 of 5

I have a information for elevation (metres) along a road at certain distances from origin and also vectors for speed and power, measured at different distances.

I need to somehow link both the tables and it may mean using bins at 1-2 metre intervals or round each point up. Any hints or tips to do this would be appreciated. Distance is the only common variable between the two tables.
Distance Elevation
1.2 24
2.3 26
4.5 32

distance Time Power Speed
1.5 1 0.5 10
2 .7 2 0.7 15
3.2 3 0.3 16

Thanks

Subject: Two vectors different dimensions

From: Oleg Komarov

Date: 7 Sep, 2010 21:15:27

Message: 2 of 5

"Aaron Anstey" <elaja2@lboro.ac.uk> wrote in message <i666ga$1u$1@fred.mathworks.com>...
> I have a information for elevation (metres) along a road at certain distances from origin and also vectors for speed and power, measured at different distances.
>
> I need to somehow link both the tables and it may mean using bins at 1-2 metre intervals or round each point up. Any hints or tips to do this would be appreciated. Distance is the only common variable between the two tables.
> Distance Elevation
> 1.2 24
> 2.3 26
> 4.5 32
>
> distance Time Power Speed
> 1.5 1 0.5 10
> 2 .7 2 0.7 15
> 3.2 3 0.3 16
>
> Thanks

A = [1.2 24
     2.3 26
     4.5 32];

B = [1.5 1 0.5 10
     2.7 2 0.7 15
     3.2 3 0.3 16];

maxBin = ceil(max([A(:,1); B(:,1)]));
minBin = floor(min([A(:,1); B(:,1)]));
[trash, locA] = histc(A(:,1),minBin:maxBin);
[trash, locB] = histc(B(:,1),minBin:maxBin);
 
C = NaN(maxBin-minBin,5);
C(locA,1:2) = A;
C(locB,[1,3:end]) = B;

C =
   1.50 24.00 1.00 0.50 10.00
   2.70 26.00 2.00 0.70 15.00
   3.20 NaN 3.00 0.30 16.00
   4.50 32.00 NaN NaN NaN

Subject: Two vectors different dimensions

From: Roger Stafford

Date: 8 Sep, 2010 02:28:04

Message: 3 of 5

"Aaron Anstey" <elaja2@lboro.ac.uk> wrote in message <i666ga$1u$1@fred.mathworks.com>...
> I have a information for elevation (metres) along a road at certain distances from origin and also vectors for speed and power, measured at different distances.
>
> I need to somehow link both the tables and it may mean using bins at 1-2 metre intervals or round each point up. Any hints or tips to do this would be appreciated. Distance is the only common variable between the two tables.
> Distance Elevation
> 1.2 24
> 2.3 26
> 4.5 32
>
> distance Time Power Speed
> 1.5 1 0.5 10
> 2 .7 2 0.7 15
> 3.2 3 0.3 16
>
> Thanks
- - - - - - - - - -
  I would think you need the services of matlab's interp1 function. You probably would wish to set the options so as to allow extrapolation as well as interpolation for your problem. Read the documentation carefully to explore its possibilities.

Roger Stafford

Subject: Two vectors different dimensions

From: Aaron Anstey

Date: 8 Sep, 2010 08:44:05

Message: 4 of 5

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <i66sbk$l88$1@fred.mathworks.com>...
> "Aaron Anstey" <elaja2@lboro.ac.uk> wrote in message <i666ga$1u$1@fred.mathworks.com>...
> > I have a information for elevation (metres) along a road at certain distances from origin and also vectors for speed and power, measured at different distances.
> >
> > I need to somehow link both the tables and it may mean using bins at 1-2 metre intervals or round each point up. Any hints or tips to do this would be appreciated. Distance is the only common variable between the two tables.
> > Distance Elevation
> > 1.2 24
> > 2.3 26
> > 4.5 32
> >
> > distance Time Power Speed
> > 1.5 1 0.5 10
> > 2 .7 2 0.7 15
> > 3.2 3 0.3 16
> >
> > Thanks
> - - - - - - - - - -
> I would think you need the services of matlab's interp1 function. You probably would wish to set the options so as to allow extrapolation as well as interpolation for your problem. Read the documentation carefully to explore its possibilities.
>
> Roger Stafford

Thanks Roger that works.

Subject: Two vectors different dimensions

From: Mashhur

Date: 8 Sep, 2010 09:21:05

Message: 5 of 5

"Aaron Anstey" <elaja2@lboro.ac.uk> wrote in message <i666ga$1u$1@fred.mathworks.com>...
> I have a information for elevation (metres) along a road at certain distances from origin and also vectors for speed and power, measured at different distances.
>
> I need to somehow link both the tables and it may mean using bins at 1-2 metre intervals or round each point up. Any hints or tips to do this would be appreciated. Distance is the only common variable between the two tables.
> Distance Elevation
> 1.2 24
> 2.3 26
> 4.5 32
>
> distance Time Power Speed
> 1.5 1 0.5 10
> 2 .7 2 0.7 15
> 3.2 3 0.3 16
>
> Thanks

if I am right you can use A[]' + B[]' (decrement and multiply or other operations also possible). I had done it by applying like this. It automatically fills by zero lack of array arguments.
Second approach, use imfill() function in Matlab if you are using images.

Enjoy,

Tags for this Thread

No tags are associated with 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