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?

 채택된 답변

Oleg Komarov
Oleg Komarov 2011년 3월 16일

3 개 추천

% 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

Samuel Maliva
Samuel Maliva 2016년 2월 26일
Please can you explain the meaning of line 3: data = data{:};
Giulia Brusadin
Giulia Brusadin 2019년 2월 12일
Might this work also with hexadecimal values? I have to register some mac address and they are represented by hex values
L.J.
L.J. 2020년 6월 19일
Curly brackets extract data.

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

추가 답변 (1개)

Priya Shaji
Priya Shaji 2018년 3월 14일

0 개 추천

Hi I want to read txt files and plot in matlab using imshow

카테고리

도움말 센터File Exchange에서 Large Files and Big Data에 대해 자세히 알아보기

질문:

2011년 3월 16일

댓글:

2020년 6월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by