how can i get the a column from a table by it's name

6 views (last 30 days)
Hello,
i'm new in matlab and i have a problem while importing data.
i need to get a specific column, it's name is the first two character of my filename, the problem is when i search a column that have a char name it works, but when the name of the column is a number it doesn't
exemple from my code :
T = readtable(A,data, 'ReadVariableNames', true);
accel= T.Acceleration ;
the column name is acceleration
it works for the pervious code
but it doen't work when the column name is a number
exemple :
acc= T.6 ;
thanks in advance
sorry for my english i'm tryng my best

Accepted Answer

Walter Roberson
Walter Roberson on 7 Mar 2022
Edited: Walter Roberson on 7 Mar 2022
acc = T.('6');
or
acc = T{:,'6'};

More Answers (1)

Image Analyst
Image Analyst on 7 Mar 2022
Edited: Image Analyst on 7 Mar 2022
If you know the column number of the column with fieldname "6" you can access it like an array
acc = T(:, 42);
or (if it's not column 42) whatever column "6" is in.
  3 Comments
rimbak
rimbak on 7 Mar 2022
6 wouldn't be a fix title it will change depending on the first two numbers of my filename ..
Image Analyst
Image Analyst on 7 Mar 2022
I understand. Did you see that I did not refer to column 6? I referred to column 42 and told you to use the actual column number that you know to hold the one with header "6".
Attach your table in a .mat file.
Don't you know the actual color number where the "6" column appears? Let's say that when you print out the table to the command window you see "6" atop column 4. Then you'd just do
acc = T(:, 4);

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!