make a GUI in matlab
显示 更早的评论
the problem is to read the text from those files, show it on screen under respective heading and allow the user to change the same. Once values are modified, after clicking ok modified value to be overwritten in respective files.
pls suggest the code for this problem.
采纳的回答
Jan
2018-5-7
This is exactly what Matlab's editor does already. Why do you want to re-create such a standard tool?
But if you really want to do this, what does "show it on screen under respective heading" mean? A uitabgroup? While it is not very complicated to create such a tab group and add some buttons for loading and saving, this is a tedious work. Try to start writing a solution and ask a specific question.
7 个评论
raviranjan singh
2018-5-7
编辑:Jan
2018-5-7
i call the text file but the problem is in the modified value
to be not overwritten in respective files.
i cant understand how to modified and change in save text file.
This details sounds trivial actually:
str = fileread(FileName);
set(handles.edit1, 'String', str, 'Min', 0, 'Max', 2);
% Set Min and Max to let it be a multi-line edit field
... Now modify the text as you want.
% Saving:
[fid, msg] = fopen(FileName, 'w')
if fid == -1
error('Cannot open file: %s: %s', FileName, msg);
end
fwrite(fid, get(handles.edit1, 'String'), 'char');
fclose(fid);
Or in words: Import the file's contents, edit it and save it. But as said already, the editor is the perfect tool for this already:
edit(FileName);
The rest is implemented there already.
If you have any otehr problem, pleas exaplain it explicitely.
at % saving section, the data is not save as seen in the edit1 section. the content read horizontally in respect to line by line.
What is the difference between "horizontally" and "line by line"? Please explain the details.
Maybe it helps to use cell strings:
cstr = strsplit(fileread(FileName), '\n');
set(handles.edit1, 'String', cstr, 'Min', 0, 'Max', 2);
% Set Min and Max to let it be a multi-line edit field
... Now modify the text as you want.
% Saving:
[fid, msg] = fopen(FileName, 'w')
if fid == -1
error('Cannot open file: %s: %s', FileName, msg);
end
cstr = get(handles.edit1, 'String');
fprintf(fid, '%s\n', cstr{:});
fclose(fid);
raviranjan singh
2018-5-8
编辑:raviranjan singh
2018-5-8
This is a problem of Notepad. All other editors can handle \n as line break reliably, but Notepad requires \r\n. Replace it by a smarter editor like WordPad or Notepad++. But if you really want to use this darn old poor editor, replace:
fprintf(fid, '%s\n', cstr{:})
by
fprintf(fid, '%s\r\n', cstr{:})
or open the file in text mode by:
[fid, msg] = fopen(FileName, 'wt')
I'd prefer to omit Notepad.
thanks. it works properly.
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Text Files 的更多信息
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
