read the text file in matlab gui as same formate

3 Ansichten (letzte 30 Tage)
raviranjan singh
raviranjan singh am 2 Mai 2018
hi all, i write a code to call text file in edit text(matlab GUI).but not call as same format, if any changes in edit text and save in other text file, it does not save as same format. so, what i change in code to save and call as same format after applying the push bottom.
fid = fopen('IO_PROCESS.txt','r');
if fid~=-1 %if the file doesn't exist ignore the reading code
set(handles.edit1,'String',fscanf(fid,'%s'))
fclose(fid);
end
  2 Kommentare
Jan
Jan am 2 Mai 2018
The question is not clear. What kind of "format" do you mean? Can you post a relevant example?
raviranjan singh
raviranjan singh am 2 Mai 2018
Bearbeitet: Walter Roberson am 2 Mai 2018
the text file as given below,
fgdfgdfgjatsggdg
gddffghh
heat_1 = 40
heat_2 = 500
heat_3 = 200
heat_4 = 5
gas_ = 40.58
gas_CO2 = 0.000
gas_H2 = 7.71
gas_H2O = 0.000
gas_N2 = 51.71
the problem is to call this text file as same format in edit text box in matlab GUI. 2nd thing is that if i change same value in the given edit text and save in other text file, it have same format as previous with changeable data.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Jan
Jan am 2 Mai 2018
I not sure, what the problem is. It would be helpful if you mention, which problem you observe.
Maybe fscanf(fid, '%s') imports the first lien only? Then:
Str = fileread('IO_PROCESS.txt');
CStr = splitstr(Str, '\n');
set(handles.edit1, 'String', CStr);
...
CStr = get(handles.edit1, 'String');
fid = fopen(FileName, 'w');
if fid == -1
error('Cannot open file: %s', FileName);
end
fprintf(fid, '%s\n', CStr{:});
fclose(fid);
  6 Kommentare
raviranjan singh
raviranjan singh am 3 Mai 2018
Bearbeitet: Walter Roberson am 3 Mai 2018
not working,i write a code ,it works but writing format of text is not maintain
fid = fopen('1.txt','r');
if fid~=-1 %if the file doesn't exist ignore the reading code
set(handles.edit1,'String',fscanf(fid,'%c'));
fclose(fid);
end
raviranjan singh
raviranjan singh am 3 Mai 2018
pls, suggest solution.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Environment and Settings finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by