필터 지우기
필터 지우기

I need to load only part of a file

조회 수: 6 (최근 30일)
Joseph
Joseph 2013년 6월 6일
I need MATLAB to load a file but the file is not a uniform matrix of number. I am using the function in matlab: load('file_name.txt'); So for example the file opens as:
46
Graphene-Cs
C 3.069663 1.451149 9.855179
C 1.828334 2.119961 9.393412
C 1.786922 3.540219 9.865837
C 0.586064 4.305576 9.363573
C 0.589753 5.714887 9.934629
C 3.115297 0.068234 9.349019
C 5.495670 1.480486 9.955026
C 4.286234 2.221273 9.447150
C 4.255019 3.612844 9.937289
C 3.019751 4.340426 9.478676
C 3.007670 5.775853 9.955533
But I need it to load the following into matlab:
3.069663 1.451149 9.855179
1.828334 2.119961 9.393412
1.786922 3.540219 9.865837
0.586064 4.305576 9.363570
0.589753 5.714887 9.934629
3.115297 0.068234 9.349019
5.495670 1.480486 9.955026
4.286234 2.221273 9.447150
4.255019 3.612844 9.937289
I am thus receiving the error:
Error using load Number of columns on line 3 of ASCII file C:\Documents\file_name.txt must be the same as previous lines.
Error in get_diff (line 9) load('file_name.txt');
Can anyone help me with this?

채택된 답변

Walter Roberson
Walter Roberson 2013년 6월 6일
fid = fopen('file_name.txt', 'rt');
datacell = textscan(fid, '%*s%g%g%g', 'HeaderLines', 2, 'Collect', 1);
fclose(fid);
YourData = datacell{1};

추가 답변 (1개)

Image Analyst
Image Analyst 2013년 6월 6일
Use fgetl() and read just however many lines you want to.

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by