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:
pairing up parameters in a 361x2 matrix

Subject: pairing up parameters in a 361x2 matrix

From: James

Date: 26 Apr, 2010 16:33:04

Message: 1 of 9

I have a 361 x 2 matrix. Below is just a portion of the data taken from my file.
The left side refers to degrees and the right side is the distance from the center.
167 161.423179453702
168 161.032351564031
169 160.821945416392
170 160.793632931030
171 160.945732200972
172 161.208529486586
173 161.780262247064
174 162.522266671831
175 163.536760034243
176 164.411165803307
177 165.398412869153
178 166.293554332660
179 167.673046265240

How do i pair the left and right side up so that whenever i enter degrees it would actually give me the corresponding distance?
For example, if i type deg(167) in the command window, i am hoping to get ans = 161.423179453702, or if i enter deg(178), i want it to give me ans = 166.293554332660

Subject: pairing up parameters in a 361x2 matrix

From: the cyclist

Date: 26 Apr, 2010 16:59:04

Message: 2 of 9

"James " <cche5398@uni.sydney.edu.au> wrote in message <hr4f80$6i0$1@fred.mathworks.com>...
> I have a 361 x 2 matrix. Below is just a portion of the data taken from my file.
> The left side refers to degrees and the right side is the distance from the center.
> 167 161.423179453702
> 168 161.032351564031
> 169 160.821945416392
> 170 160.793632931030
> 171 160.945732200972
> 172 161.208529486586
> 173 161.780262247064
> 174 162.522266671831
> 175 163.536760034243
> 176 164.411165803307
> 177 165.398412869153
> 178 166.293554332660
> 179 167.673046265240
>
> How do i pair the left and right side up so that whenever i enter degrees it would actually give me the corresponding distance?
> For example, if i type deg(167) in the command window, i am hoping to get ans = 161.423179453702, or if i enter deg(178), i want it to give me ans = 166.293554332660

The exact syntax will depend on whether your array is stored in a file, in workspace, etc. However, if "A" is your array, then the operative commands will be something like:

>> indexToCorrectRow = (A(:,1)==167);
>> value = A(indexToCorrectRow,2);

The first line finds the row of A that has 167 in the first column. The second line finds the element in the second column of that row.

the cyclist

Subject: pairing up parameters in a 361x2 matrix

From: Sean

Date: 26 Apr, 2010 17:00:21

Message: 3 of 9

"James " <cche5398@uni.sydney.edu.au> wrote in message <hr4f80$6i0$1@fred.mathworks.com>...
> I have a 361 x 2 matrix. Below is just a portion of the data taken from my file.
> The left side refers to degrees and the right side is the distance from the center.
> 167 161.423179453702
> 168 161.032351564031
> 169 160.821945416392
> 170 160.793632931030
> 171 160.945732200972
> 172 161.208529486586
> 173 161.780262247064
> 174 162.522266671831
> 175 163.536760034243
> 176 164.411165803307
> 177 165.398412869153
> 178 166.293554332660
> 179 167.673046265240
>
> How do i pair the left and right side up so that whenever i enter degrees it would actually give me the corresponding distance?
> For example, if i type deg(167) in the command window, i am hoping to get ans = 161.423179453702, or if i enter deg(178), i want it to give me ans = 166.293554332660

One way:
>>M = [1:10;rand(1,10)]'; %[angle, dist]
>>deg = @(angle) M((M(:,1)==angle),2);
>>deg(3)

Subject: pairing up parameters in a 361x2 matrix

From: Steven Lord

Date: 26 Apr, 2010 17:03:48

Message: 4 of 9


"the cyclist" <thecyclist@gmail.com> wrote in message
news:hr4goo$gbu$1@fred.mathworks.com...
> "James " <cche5398@uni.sydney.edu.au> wrote in message
> <hr4f80$6i0$1@fred.mathworks.com>...
>> I have a 361 x 2 matrix. Below is just a portion of the data taken from
>> my file.
>> The left side refers to degrees and the right side is the distance from
>> the center.
>> 167 161.423179453702
>> 168 161.032351564031
>> 169 160.821945416392
>> 170 160.793632931030
>> 171 160.945732200972
>> 172 161.208529486586
>> 173 161.780262247064
>> 174 162.522266671831
>> 175 163.536760034243
>> 176 164.411165803307
>> 177 165.398412869153
>> 178 166.293554332660
>> 179 167.673046265240
>>
>> How do i pair the left and right side up so that whenever i enter degrees
>> it would actually give me the corresponding distance?
>> For example, if i type deg(167) in the command window, i am hoping to get
>> ans = 161.423179453702, or if i enter deg(178), i want it to give me ans
>> = 166.293554332660
>
> The exact syntax will depend on whether your array is stored in a file, in
> workspace, etc. However, if "A" is your array, then the operative
> commands will be something like:
>
>>> indexToCorrectRow = (A(:,1)==167);
>>> value = A(indexToCorrectRow,2);
>
> The first line finds the row of A that has 167 in the first column. The
> second line finds the element in the second column of that row.

The code the cyclist wrote will work if all the degree values you're
planning to use are in your data, but could run into issues if you ask for
the distance corresponding to an angle that's not in your data or is
slightly different from what is in your data. If your usage could fall into
that use case, I suggest using INTERP1.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ

Subject: pairing up parameters in a 361x2 matrix

From: James

Date: 26 Apr, 2010 18:46:05

Message: 5 of 9

"Steven Lord" <slord@mathworks.com> wrote in message <hr4h19$4im$1@fred.mathworks.com>...
>
> "the cyclist" <thecyclist@gmail.com> wrote in message
> news:hr4goo$gbu$1@fred.mathworks.com...
> > "James " <cche5398@uni.sydney.edu.au> wrote in message
> > <hr4f80$6i0$1@fred.mathworks.com>...
> >> I have a 361 x 2 matrix. Below is just a portion of the data taken from
> >> my file.
> >> The left side refers to degrees and the right side is the distance from
> >> the center.
> >> 167 161.423179453702
> >> 168 161.032351564031
> >> 169 160.821945416392
> >> 170 160.793632931030
> >> 171 160.945732200972
> >> 172 161.208529486586
> >> 173 161.780262247064
> >> 174 162.522266671831
> >> 175 163.536760034243
> >> 176 164.411165803307
> >> 177 165.398412869153
> >> 178 166.293554332660
> >> 179 167.673046265240
> >>
> >> How do i pair the left and right side up so that whenever i enter degrees
> >> it would actually give me the corresponding distance?
> >> For example, if i type deg(167) in the command window, i am hoping to get
> >> ans = 161.423179453702, or if i enter deg(178), i want it to give me ans
> >> = 166.293554332660
> >
> > The exact syntax will depend on whether your array is stored in a file, in
> > workspace, etc. However, if "A" is your array, then the operative
> > commands will be something like:
> >
> >>> indexToCorrectRow = (A(:,1)==167);
> >>> value = A(indexToCorrectRow,2);
> >
> > The first line finds the row of A that has 167 in the first column. The
> > second line finds the element in the second column of that row.
>
> The code the cyclist wrote will work if all the degree values you're
> planning to use are in your data, but could run into issues if you ask for
> the distance corresponding to an angle that's not in your data or is
> slightly different from what is in your data. If your usage could fall into
> that use case, I suggest using INTERP1.
>
> --
> Steve Lord
> slord@mathworks.com
> comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
>
Yep, INTERP1, that's what i tried initially. But i couldn't get that to work, i did look through the help before posting this thread,

YI = INTERP1(X,Y,XI) interpolates to find YI, the values of the underlying function Y at the points in the array XI. X must be a vector of length N.

I am having trouble understanding what XI is. In the above case, X is degrees and Y is distance from center. What's XI?

Subject: pairing up parameters in a 361x2 matrix

From: James

Date: 26 Apr, 2010 18:52:21

Message: 6 of 9

"the cyclist" <thecyclist@gmail.com> wrote in message <hr4goo$gbu$1@fred.mathworks.com>...
> "James " <cche5398@uni.sydney.edu.au> wrote in message <hr4f80$6i0$1@fred.mathworks.com>...
> > I have a 361 x 2 matrix. Below is just a portion of the data taken from my file.
> > The left side refers to degrees and the right side is the distance from the center.
> > 167 161.423179453702
> > 168 161.032351564031
> > 169 160.821945416392
> > 170 160.793632931030
> > 171 160.945732200972
> > 172 161.208529486586
> > 173 161.780262247064
> > 174 162.522266671831
> > 175 163.536760034243
> > 176 164.411165803307
> > 177 165.398412869153
> > 178 166.293554332660
> > 179 167.673046265240
> >
> > How do i pair the left and right side up so that whenever i enter degrees it would actually give me the corresponding distance?
> > For example, if i type deg(167) in the command window, i am hoping to get ans = 161.423179453702, or if i enter deg(178), i want it to give me ans = 166.293554332660
>
> The exact syntax will depend on whether your array is stored in a file, in workspace, etc. However, if "A" is your array, then the operative commands will be something like:
>
> >> indexToCorrectRow = (A(:,1)==167);
> >> value = A(indexToCorrectRow,2);
>
> The first line finds the row of A that has 167 in the first column. The second line finds the element in the second column of that row.
>
> the cyclist

Thanks, mate. But as Steven Lord said, the above code may not work 100% in some of the situation he just mentioned. So i think i will stick to using INTERP1.

Subject: pairing up parameters in a 361x2 matrix

From: the cyclist

Date: 26 Apr, 2010 19:08:04

Message: 7 of 9

"James " <cche5398@uni.sydney.edu.au> wrote in message <hr4n1d$dn6$1@fred.mathworks.com>...
> "Steven Lord" <slord@mathworks.com> wrote in message <hr4h19$4im$1@fred.mathworks.com>...
> >
> > "the cyclist" <thecyclist@gmail.com> wrote in message
> > news:hr4goo$gbu$1@fred.mathworks.com...
> > > "James " <cche5398@uni.sydney.edu.au> wrote in message
> > > <hr4f80$6i0$1@fred.mathworks.com>...
> > >> I have a 361 x 2 matrix. Below is just a portion of the data taken from
> > >> my file.
> > >> The left side refers to degrees and the right side is the distance from
> > >> the center.
> > >> 167 161.423179453702
> > >> 168 161.032351564031
> > >> 169 160.821945416392
> > >> 170 160.793632931030
> > >> 171 160.945732200972
> > >> 172 161.208529486586
> > >> 173 161.780262247064
> > >> 174 162.522266671831
> > >> 175 163.536760034243
> > >> 176 164.411165803307
> > >> 177 165.398412869153
> > >> 178 166.293554332660
> > >> 179 167.673046265240
> > >>
> > >> How do i pair the left and right side up so that whenever i enter degrees
> > >> it would actually give me the corresponding distance?
> > >> For example, if i type deg(167) in the command window, i am hoping to get
> > >> ans = 161.423179453702, or if i enter deg(178), i want it to give me ans
> > >> = 166.293554332660
> > >
> > > The exact syntax will depend on whether your array is stored in a file, in
> > > workspace, etc. However, if "A" is your array, then the operative
> > > commands will be something like:
> > >
> > >>> indexToCorrectRow = (A(:,1)==167);
> > >>> value = A(indexToCorrectRow,2);
> > >
> > > The first line finds the row of A that has 167 in the first column. The
> > > second line finds the element in the second column of that row.
> >
> > The code the cyclist wrote will work if all the degree values you're
> > planning to use are in your data, but could run into issues if you ask for
> > the distance corresponding to an angle that's not in your data or is
> > slightly different from what is in your data. If your usage could fall into
> > that use case, I suggest using INTERP1.
> >
> > --
> > Steve Lord
> > slord@mathworks.com
> > comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
> >
> Yep, INTERP1, that's what i tried initially. But i couldn't get that to work, i did look through the help before posting this thread,
>
> YI = INTERP1(X,Y,XI) interpolates to find YI, the values of the underlying function Y at the points in the array XI. X must be a vector of length N.
>
> I am having trouble understanding what XI is. In the above case, X is degrees and Y is distance from center. What's XI?

X is the first column of your array. Y is the second column of your array. XI is the input to your function (the "degrees" value that your user is interested in). YI is the output of your function (the "distance" that your users wants to know).

the cyclist

Subject: pairing up parameters in a 361x2 matrix

From: Sean

Date: 26 Apr, 2010 19:21:04

Message: 8 of 9

"James " <cche5398@uni.sydney.edu.au> wrote in message <hr4n1d$dn6$1@fred.mathworks.com>...
> "Steven Lord" <slord@mathworks.com> wrote in message <hr4h19$4im$1@fred.mathworks.com>...
> >
> > "the cyclist" <thecyclist@gmail.com> wrote in message
> > news:hr4goo$gbu$1@fred.mathworks.com...
> > > "James " <cche5398@uni.sydney.edu.au> wrote in message
> > > <hr4f80$6i0$1@fred.mathworks.com>...
> > >> I have a 361 x 2 matrix. Below is just a portion of the data taken from
> > >> my file.
> > >> The left side refers to degrees and the right side is the distance from
> > >> the center.
> > >> 167 161.423179453702
> > >> 168 161.032351564031
> > >> 169 160.821945416392
> > >> 170 160.793632931030
> > >> 171 160.945732200972
> > >> 172 161.208529486586
> > >> 173 161.780262247064
> > >> 174 162.522266671831
> > >> 175 163.536760034243
> > >> 176 164.411165803307
> > >> 177 165.398412869153
> > >> 178 166.293554332660
> > >> 179 167.673046265240
> > >>
> > >> How do i pair the left and right side up so that whenever i enter degrees
> > >> it would actually give me the corresponding distance?
> > >> For example, if i type deg(167) in the command window, i am hoping to get
> > >> ans = 161.423179453702, or if i enter deg(178), i want it to give me ans
> > >> = 166.293554332660
> > >
> > > The exact syntax will depend on whether your array is stored in a file, in
> > > workspace, etc. However, if "A" is your array, then the operative
> > > commands will be something like:
> > >
> > >>> indexToCorrectRow = (A(:,1)==167);
> > >>> value = A(indexToCorrectRow,2);
> > >
> > > The first line finds the row of A that has 167 in the first column. The
> > > second line finds the element in the second column of that row.
> >
> > The code the cyclist wrote will work if all the degree values you're
> > planning to use are in your data, but could run into issues if you ask for
> > the distance corresponding to an angle that's not in your data or is
> > slightly different from what is in your data. If your usage could fall into
> > that use case, I suggest using INTERP1.
> >
> > --
> > Steve Lord
> > slord@mathworks.com
> > comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
> >
> Yep, INTERP1, that's what i tried initially. But i couldn't get that to work, i did look through the help before posting this thread,
>
> YI = INTERP1(X,Y,XI) interpolates to find YI, the values of the underlying function Y at the points in the array XI. X must be a vector of length N.
>
> I am having trouble understanding what XI is. In the above case, X is degrees and Y is distance from center. What's XI?


XI is the point you care about e.g: 167 or 167.3 or 89.91 degrees.

You have to be careful with your data since it changes quickly over a long period. If you use all of the angles and all of the distances for your x, y then the result will most likely be garbage. You probably just want to use 1-3 values on each side of the angle you'll be interpolating.

e.g. say you want it at 167.5, with 1 angle on each side:
angles = your_matrix_earlier(:,1);
distances = your_matrix_earlier(:,2);
my_distance = interp1(angles(167:168),distances(167:168), 167.5);

Subject: pairing up parameters in a 361x2 matrix

From: the cyclist

Date: 26 Apr, 2010 19:40:19

Message: 9 of 9

"Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <hr4p30$pki$1@fred.mathworks.com>...

> XI is the point you care about e.g: 167 or 167.3 or 89.91 degrees.
>
> You have to be careful with your data since it changes quickly over a long period. If you use all of the angles and all of the distances for your x, y then the result will most likely be garbage. You probably just want to use 1-3 values on each side of the angle you'll be interpolating.
>
> e.g. say you want it at 167.5, with 1 angle on each side:
> angles = your_matrix_earlier(:,1);
> distances = your_matrix_earlier(:,2);
> my_distance = interp1(angles(167:168),distances(167:168), 167.5);

The default method, linear interpolation, will ignore everything except the nearest X points. No need to complicate the code in this way.

the cyclist

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