format data for floating to integer to ascii
4 ビュー (過去 30 日間)
古いコメントを表示
i have data input in edit text like this :
B2
4
3
0
10000
M12
3
1
1
1000
0
240
120
1520
0
but when i use save ascii like this command :
save(red.txt,'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','-ASCII'),
the variable from input using
b=str2num(get(edit2,'String'));
and edit text at least 16
edit1=uicontrol('parent',win1,...
'units','points',...
'position',[130 200 30 15],...
'backgroundcolor',[1 1 1],...
'style','Edit',...
'string','',...
'fontname','arial',...
'fontsize',10);;
i get this :
6.6000000e+01 5.0000000e+01
4.0000000e+00
3.0000000e+00
0.0000000e+00
1.0000000e+03
7.7000000e+01 4.9000000e+01 5.0000000e+01
3.0000000e+00
1.0000000e+00
1.0000000e+00
1.0000000e+03
0.0000000e+00
2.4000000e+02
1.2000000e+02
1.5200000e+03
0.0000000e+00
0.0000000e+00
how do you make the same as the input?
回答 (2 件)
Walter Roberson
2015 年 10 月 30 日
This is the same question you asked before and I answered in http://uk.mathworks.com/matlabcentral/answers/251588-save-ascii-from-edit-uicontrol#comment_319269
Values you get from the String property of a uicontrol() are always strings until you convert them to numeric. Just write them out as strings.
b = get(edit2,'String');
fid = fopen('red.txt', 'wt');
fprintf(fid, '%s\n%s\n', a, b);
fprintf(fid, '%d\n%d\n%d\n', c, d, e);
fprintf(fid, '%s\n', f);
... and so on
fclose(fid);
3 件のコメント
dpb
2015 年 10 月 30 日
From
help save
...
'-ascii' 8-digit ASCII format.
...
For ASCII file formats, the save function has the following
limitations:
* Each variable must be a two-dimensional double or char array.
* MATLAB translates characters to their corresponding internal
ASCII codes. For example, 'abc' appears in an ASCII file as:
9.7000000e+001 9.8000000e+001 9.9000000e+001
To write the data otherwise you'll have to use formatted with fprintf as the other higher-level routines such as csvwrite can only handle numeric arrays and you've got character data here.
What, specifically, are you trying to accomplish; writing the data to a file or saving it for use internally to the application? If the latter you can forget about the format and just use save/load and retrieve what was written transparently.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Data Type Conversion についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!