How can I creat a Excel Table Data from a not really well formated Text Data
조회 수: 1 (최근 30일)
이전 댓글 표시
Dear Matlab comunity! As it asked in the question, I have a file Textdata.txt looks like this:
object1
xmin = -20.2
xmax = 30.22E-2
ymin = -10.35274
ymax = 40.5723
zmin = 50.38
zmax = 60.1342
end Objekt1
objekt2
xmin = .....
xmax = .....
ymin = .....
ymax = .....
zmin = ......
zmax = .....
end object2
object3...
object4...
...
objectn...
and i want to write a matlab progamm, which creats an Excel Data Table from the file Textdata.txt. The Excel Table should look like:
xmin xmax ymin ymax zmin zmax
object1 ... ... ... ... ... ...
object2 ... ... ... ... ... ...
.
.
.
objectn ... ... ... .. ... ...
I have tried the function "fscanf" but not yet successful. Thank you verry much!
댓글 수: 0
채택된 답변
Friedrich
2013년 6월 6일
편집: Friedrich
2013년 6월 6일
Hi,
there is an example in the doc which matches your format quite perfectly:
So something like this:
fid = fopen('test.txt','r')
tmp = textscan(fid,'%s xmin = %f xmax = %f ymin = %f ymax = %f zmin = %f zmax = %f %*s %*s','delimiter','\n')
fclose(fid);
And then you can do something like:
data = cell(numel(tmp{1}),numel(tmp));
for i=1:numel(tmp)
if iscell(tmp{i})
data(:,i) = tmp{i};
else
data(:,i) = num2cell(tmp{i});
end
end
disp(data)
xlswrite('test.xls',data)
댓글 수: 6
Friedrich
2013년 6월 10일
편집: Friedrich
2013년 6월 10일
No, at least not for my test example:
object1
xmin = -20.2
xmax = 30.22E-2
ymin = -10.35274
ymax = 40.5723
zmin = 50.38
zmax = 60.1342
end Objekt1
objekt2
xmin = 1
xmax = 2
ymin = 3
ymax = 4
zmin = 5
zmax = 6
end object2
When using the code above I get for disp(data)
>>disp(data)
Columns 1 through 6
'object1' [-20.2000] [0.3022] [-10.3527] [40.5723] [50.3800]
'objekt2' [ 1] [ 2] [ 3] [ 4] [ 5]
Column 7
[60.1342]
[ 6]
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!