Problems writing values from edit text box to a txt file
1 view (last 30 days)
Show older comments
I have inserted some code under the callback function for an edit text box, it runs without any errors but when I inspect the .txt file afterwards it is blank?
endfunction edit2_Callback(hObject, eventdata, handles)
b = get(hObject,'String');
fid = fopen('b.txt');
fprintf(fid, b{:});
fclose(fid);
Originally the code was as shown below, but this gave the error 'Error using fwrite Cannot write value: unsupported class cell', adding the {:} removed this error.
endfunction edit2_Callback(hObject, eventdata, handles)
b = get(hObject,'String');
fid = fopen('b.txt');
fprintf(fid, b);
fclose(fid);
I have also tried replacing the {:} with {1}, but this still gives an empty text box?
Accepted Answer
Star Strider
on 8 Feb 2016
Edited: Star Strider
on 8 Feb 2016
You seem to be missing a format descriptor!
See if:
fprintf(fid, '%s\n', b{:});
improves the performance of your code.
More Answers (0)
See Also
Categories
Find more on Text Data Preparation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!