how to get the usual form of a matrix from a txt file?

조회 수: 1 (최근 30일)
Ano
Ano 2016년 11월 23일
댓글: Ano 2016년 11월 23일
hello, I have a matrix defined in a txt file as it follows:
row column value
1 1 -4.630
2 1 -4.307
3 1 -3.804
1 2 -4.630
2 2 -4.741
3 2 -4.630
1 3 -3.804
2 3 -4.307
3 3 -4.630
and I would like to put it back into the the matrix form provided by matlab (the square form), any suggestions ? Thank you in advance!

채택된 답변

KSSV
KSSV 2016년 11월 23일
data = importdata('data.txt');
num = data.data ;
matrix = reshape(num(:,3),3,[])
doc reshape

추가 답변 (1개)

Ano
Ano 2016년 11월 23일
what if the file has got some text before the matrix, how can I still extract the matrix ?? thank you in advance !
  댓글 수: 2
KSSV
KSSV 2016년 11월 23일
The above code has to work if the text exists before the matrix. I checked the above, copying your data with text in the file.
Ano
Ano 2016년 11월 23일
I would appreciate if you could try with the attached file which contains the headers, for me it does not work? any suggestions. thank you

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

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by