How to use extract values from table and create a vector?
20 次查看(过去 30 天)
显示 更早的评论
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 个评论
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
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!