Read txt file and exclude string line..

I have attached a file openable in text . The data of the file is as follows:
Note: Joint label, Equation numbers for U1, U2, U3, R1, R2, R3. (See .TXA file)
2 1 0 0 0 2
0
3 0 0 0 0 0
0
4 3 0 4 0 5
0
What i want is to make a matrix from the file by reading the file. The matrix should have three rows and 7 columns. The string line should be excluded.
The first row contains : 2 1 0 0 0 2 0
means the first numeric row in the file and the single numeric entity in the next row should be stored in the 1st row of the matrix made.
and same is for the 2nd and 3rd row of the matrix.
The final matrix is as follows:
2 1 0 0 0 2 0
3 0 0 0 0 0 0
4 3 0 4 0 5 0
Thanks in advance,

댓글 수: 6

Jonas Allgeier
Jonas Allgeier 2020년 3월 5일
편집: Jonas Allgeier 2020년 3월 5일
Does this do what you want?
fid = fopen('My2.TXE');
temp = textscan(fid,'%d','Headerlines',1,'delimiter','\n');
fclose(fid);
result = reshape(temp{1},7,[])';
Ahmed Anas
Ahmed Anas 2020년 3월 5일
I want a matrix from the data.. it does not work accordingly..
Jonas Allgeier
Jonas Allgeier 2020년 3월 5일
the last line gives you the requested matrix... if this does not solve your problem, could you elaborate what is missing? To make it more clear, I edited the code segment to save the result in a variable called result.
Ahmed Anas
Ahmed Anas 2020년 3월 5일
Ok thanks for your answer..
It gives me a column vector, which i will convert to a matrix..
Guillaume
Guillaume 2020년 3월 5일
@Ahmed, I don't know what software you're using that produces the file in this question and your previous one but if it's possible at all you should consider outputting the data in a different format. One that doesn't use a mix of tab and spaces to separate the numbers and one that keeps a row to one line instead of splitting it arbitrarily onto multiple lines.
While it's possible to read any kind of file in matlab, the amount of effort increases if the format is as badly designed as in the present file.
Ahmed Anas
Ahmed Anas 2020년 3월 5일
@Guillaume , Am structure engineering doing my research project on matlab in desktop application development. This file is generated by Sap 2000, a civil engineers software.. Yeah i know this is so badly formated but this data is very helpful for me in my research..

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

답변 (0개)

카테고리

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

제품

태그

질문:

2020년 3월 5일

댓글:

2020년 3월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by