From: James on 26 Apr 2010 12:33 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
From: the cyclist on 26 Apr 2010 12:59 "James " <cche5398(a)uni.sydney.edu.au> wrote in message <hr4f80$6i0$1(a)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
From: Sean on 26 Apr 2010 13:00 "James " <cche5398(a)uni.sydney.edu.au> wrote in message <hr4f80$6i0$1(a)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)
From: Steven Lord on 26 Apr 2010 13:03 "the cyclist" <thecyclist(a)gmail.com> wrote in message news:hr4goo$gbu$1(a)fred.mathworks.com... > "James " <cche5398(a)uni.sydney.edu.au> wrote in message > <hr4f80$6i0$1(a)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(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
From: James on 26 Apr 2010 14:46
"Steven Lord" <slord(a)mathworks.com> wrote in message <hr4h19$4im$1(a)fred.mathworks.com>... > > "the cyclist" <thecyclist(a)gmail.com> wrote in message > news:hr4goo$gbu$1(a)fred.mathworks.com... > > "James " <cche5398(a)uni.sydney.edu.au> wrote in message > > <hr4f80$6i0$1(a)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(a)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? |