How to use extract values from table and create a vector?

This is a snippet of the table I am using. I would like to extract the first three values of the first row and make them into a vector. Then I am trying repeat this for the rest of the table so I am trying to automate this process. I want to repeat this process going across the row as well. I have tried to use linear indexing but that does not seem to work for a table. Any help would be much appreciated! :)
Ex. V1 = [38 -4.9 1.6]
V2 = [26 2.8 9.11]
V3 = [69.4 1.38 1.73]
1 38.0612863200000 -4.92489214000000 1.61459159000000 -26.6372975300000 -2.88587070000000 9.11760291000000
2 69.1311090200000 1.38122400000000 1.73015519000000 -50.7111482300000 -4.91683564000000 17.3218763400000
3 69.4693915900000 -2.04777409000000 3.26215064000000 -50.9685884600000 -5.18785435000001 18.6047077000000
4 71.1999738400000 -7.11194808000000 9.68437550000000 -53.7429212500000 -6.84970569000000 18.6666163000000
5 71.1375598900000 -4.20452543000000 11.4352333400000 -53.0160618700000 -5.68292624000000 17.5609821200000
6 71.0272869600000 -5.98530164000000 10.7742126400000 -52.8287907300000 -5.76257843000000 17.6566466600000
7 70.6139454600000 -6.44289640000000 11.0002299000000 -53.0225088000000 -5.75786210000000 18.7346759400000
8 70.6024690700000 -6.99547140000000 10.6277907600000 -52.5723710300000 -5.68863023000000 18.5903466600000
9 70.3099531800000 -7.52192047000000 9.39208690999999 -52.7202983100000 -6.57299556000000 18.4565642600000
10 69.9161176300000 -5.28306989000000 9.52133345000000 -51.5949428800000 -5.61149680000000 17.1547983200000
11 68.8451106200000 -4.39953777000000 9.42625631000000 -50.9515004400000 -6.03035162000000 17.8968844800000
12 68.8389343600000 -4.99675323000000 9.06446024000000 -50.9516305000000 -5.62032990000000 17.7586725500000
13 68.7707931300000 -5.02368913000000 8.41310290000000 -50.6873997400000 -5.54006198000000 17.5406247600000
Update: I have converted this to a maxtrix and linear indexing now works, but my matrix is 133 columns long by 13 rows so I would prefer a shortcut if anyone knows of one!

댓글 수: 3

What are you trying to do with the values?
Hi Bob! The first three coordinates are x y z coordinates of a palm. The next three are x y z coordinates of a thumb knuckle. I am trying to put these coordinates into a vector so I can find the angles between the vectors and therefore the angle of each knuckle.
This is the code I have come up with. I am far from an expert in matlab so if you could help me automate this I would appreciate it!
VPALM1 = C(1, 2:4);
VTHUMB1 = C(1, 5:7);
VTHUMB2 = C(1, 8:10);
VPALM2THUMB = VTHUMB1-VPALM1; %vector from thumb to palm
VTHUMB2R = VTHUMB2 + VTHUMB1; % added knuckle 1 of thumb to base of thumb becuase local coordinates
VPALM2THUMB2 = VTHUMB2R - VPALM1; %vector from thumb knuckle to palm
atan2(norm(cross(VPALM2THUMB,VPALM2THUMB2)),dot(VPALM2THUMB,VPALM2THUMB2));
example.PNG
This is the same data as above but with the column headers included.
Adam Danz
Adam Danz 2019년 6월 24일
편집: Adam Danz 2019년 6월 24일
The solution I proposed below reshapes your data into a new matrix where each row is one of your V variables. This method is much better than creating new variables dynamically and splitting apart the data.
Here's an explanation why not to use dynamic variables:

댓글을 달려면 로그인하십시오.

 채택된 답변

Adam Danz
Adam Danz 2019년 6월 24일
편집: Adam Danz 2019년 6월 24일
Reshape your matrix from [n x 6] to [m x 3] where m=2*n. Row 1 of your new matrix will be your V1 vector, row 2 will be your V2 vector and so on.
% Make fake data
data = reshape(1:300,6,50).';
% Reshape it
newData = reshape(data.',3,[]).'; % pay attention to the 2 transposes
V1 is newData(1,:)
V2 is newData(2,:)
Vn is newData(n,:)

댓글 수: 5

Thank you very much for all your help! I apologize for the confusion but I do not understand the first step of your solution. My matrix is 13 x 133 and I am ignoring the first column so really the data I need is 12 x 133. I have tried this code but I get this error.
data = reshape(1:133, 12, 13).';
To RESHAPE the number of elements must not change.
I figured it out! I deleted the first row since I wouldnt be using it and used this! Thank you again Adam!
C(:,1) =[];
newData = reshape(C.',3,[]).';
Deleting works, you would have also been able to index the portion you would like, that way you can keep the first column if you need it for something else.
newdata = reshape(C(:,2:end).',3,[]).';
Nice work, Nicole and thanks for the tip, Bob !
Thank you Bob! I think I will include that because I prefer having the numbers in my table just in case.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

태그

질문:

2019년 6월 24일

댓글:

2019년 6월 24일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by