フィルターのクリア

How can I creat a Excel Table Data from a not really well formated Text Data

1 回表示 (過去 30 日間)
Ali Mania
Ali Mania 2013 年 6 月 6 日
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!

採用された回答

Friedrich
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
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]
Ali Mania
Ali Mania 2013 年 6 月 12 日
yes, you are right. I found the mistake in my code.Thanks !

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by