Read Text File into a Matrix
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
student
el 16 de Mzo. de 2011
Comentada: L.J.
el 19 de Jun. de 2020
I would like to be able to read a text file into matlab and turn it into a matrix. The text file would look like this:
%Joint Properties
% Format is %joint# x_coord y_coord xdof# ydof#
1 0 0 4 5
2 120 0 1 6
3 120 120 2 3
I would like to turn the numbers into a matrix. How would I do this?
Also, how would I then access a single column in this matrix?
Is there a way to have Matlab count the number of rows in the matrix?
0 comentarios
Respuesta aceptada
Oleg Komarov
el 16 de Mzo. de 2011
% read in data
fid = fopen('filepath');
data = textscan(fid,'%f%f%f%f','HeaderLines',2,'CollectOutput',1);
data = data{:};
fid = fclose(fid);
% retrieve column 1
data(:,1)
% Number of rows
size(data,1)
I assumed the example of the text file doesn't have intervealing blank lines.
Oleg
3 comentarios
Giulia Brusadin
el 12 de Feb. de 2019
Might this work also with hexadecimal values? I have to register some mac address and they are represented by hex values
Más respuestas (1)
Priya Shaji
el 14 de Mzo. de 2018
Hi I want to read txt files and plot in matlab using imshow
0 comentarios
Ver también
Categorías
Más información sobre Large Files and Big Data 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!