Exporting Edited Data to Notepad in Appdesigner

1 vue (au cours des 30 derniers jours)
I
I le 11 Mar 2022
Déplacé(e) : Rik le 23 Juin 2023
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?
  5 commentaires
Stephen23
Stephen23 le 23 Mar 2022
" I am not sure how to handle that."
By reading the WRITEMATRIX documentation and providing the specified inputs:
I
I le 27 Mar 2022
I am not sure if the available definition is helpful since I have variables rather than constant numbers. If you know a way to use WRITEMATRIX with variables then I am willing to give it a try.

Connectez-vous pour commenter.

Réponses (2)

Voss
Voss le 11 Mar 2022
Modifié(e) : Voss le 13 Mar 2022
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
Voss
Voss le 13 Mar 2022
Déplacé(e) : Rik le 23 Juin 2023
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
I le 18 Mar 2022
Déplacé(e) : Rik le 23 Juin 2023
Hi, this might help you better understand my quest regarding converting the data before saving it.
I have tried a a few more things and I got here with the following error:
D = (app.T(:,:));
fileid = fopen ('name','w');
fprintf(fileid, '%6.2f\n' , D);
Error using fprintf
Unable to convert 'table' value to 'double'.
I used table2array upon importing my row of data and I do not understand which function I need to use in order to be able to export it back into that original format as a row of data. Unfortunately, I have yet to be successful.

Connectez-vous pour commenter.


I
I le 21 Mar 2022
I managed to run the app without an error.
This is how my input data looks before importing it:
0.09 0.45 45 0 0.006 0.242 4.67 4 0.89925 1
I am having an issue with properly editing the data and the format of saving it now.
I am trying to edit the data. Here are two variables:
function EditButtonPushed(app, event)
app.T.ct(1) = app.ctEditField.Value;
app.T.cr(2) = app.crEditField.Value;
Then, this is how I manged to export the data:
Q = table2array(app.T(:,:));
fileid = fopen('name.txt','w');
fprintf(fileid, '%6.5f\n' , Q);
My output now looks like this and editing the data before exporting it does not affect the numbers in the output.
Here is the data for the first two variables:
0.09
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.45
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
The output changes my row into a column and adds 9 zeroes between each data.
What can I try to correctly edit the data and export it into a row of numbers as shown in the format of the initial data?

Catégories

En savoir plus sur Low-Level File I/O dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by