readtable .txt file, reading string row issue
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Birsen Ayaz-Maierhafer
el 25 de En. de 2024
Editada: the cyclist
el 26 de En. de 2024
Hi,
I have a text file with several columns and rows. The first coulmn are string while the rest of the columns are just data. I would like to pull the row named "al28" for column 4:end. But I have issue with selectiong the string value and get error.
T = readtable('Test.txt');
T2=T('al28',4:end)
Error using Test
Unrecognized table row name 'al28'.
Thank you for your help
Birsen
0 comentarios
Respuesta aceptada
the cyclist
el 25 de En. de 2024
Editada: the cyclist
el 26 de En. de 2024
You need to specify that the first column is the row names:
% Specify the file name
file_path = 'Test.txt';
% Read the file into a table
T = readtable(file_path, 'Delimiter', '\t', 'ReadRowNames', true);
T2 = T('al28',4:end)
2 comentarios
Dyuman Joshi
el 26 de En. de 2024
Editada: the cyclist
el 26 de En. de 2024
% Specify the file name
file_path = 'Test.txt';
% Read the file into a table
T = readtable(file_path, 'Delimiter', '\t', 'ReadRowNames', true);
T2 = T('al28',4:end)
"How can I get the list of the first columns (na24m, mg27, ...)?"
Using the properties of the table -
names = T.Properties.RowNames
"I tried T3=T(:,1) but it pulled the column Var1 not the list of the elements."
You need to access the data stored in the table. One way is to use curly brackets.
Read more here - Access Data in Tables
T3 = T{:,1}
Más respuestas (0)
Ver también
Categorías
Más información sobre Cell Arrays en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!