Exporting Edited Data to Notepad in Appdesigner
Afficher commentaires plus anciens
First of all, I had a row of numbers in a notepad
I upploaded those numbers and had to use a table2array function for them to read correctly into my value fields
I now want to be able to edit the number and save the new number into that save notepad
I believe this is the relevant code:
% Button pushed function: EditButton
function EditButtonPushed(app, event)
app.T.ct(1) = app.ctEditField.Value;
and
function SaveButtonPushed(app, event)
Q = (app.T(:,:));
%fileid = fopen('*.txt');
fprintf('*.txt', '%6.2f\n' , Q);
These are for the edit button to edit the number that I read into the field and then the save button for exporting the new data.
I actually do not have an error message, so I am not sure what to try. The result is that the new data in the notepad is completely empty.
Is there a function to fix this?
Réponses (2)
In order to write to a file you will say something like:
fileid = fopen('text_file_name.txt','w');
fprintf(fileid,'%f\n',data_to_write);
fclose(fileid);
That is, you need to open a specific file (no wildcards like '*') using fopen(), then write to the file (e.g., with fprintf()) using the file ID returned from fopen(), and finally close the file using fclose() - again using the same file ID - when you are done.
3 commentaires
data_to_write is intended to represent the data you want to write to the file. So in your case you might say the following in order to write the first column of data from the table app.T to the file 'name.txt':
Q = app.T{:,1};
fileid = fopen('name.txt','w');
fprintf(fileid, '%f\n' , Q);
fclose(fileid);
I
le 21 Mar 2022
Catégories
En savoir plus sur Text Files dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!