Exporting Edited Data to Notepad in Appdesigner

1 次查看(过去 30 天)
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 个评论
Stephen23
Stephen23 2022-3-23
" I am not sure how to handle that."
By reading the WRITEMATRIX documentation and providing the specified inputs:
I
I 2022-3-27
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.

请先登录,再进行评论。

回答(2 个)

Voss
Voss 2022-3-11
编辑:Voss 2022-3-13
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 个评论
Voss
Voss 2022-3-13
移动:Rik 2023-6-23
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 2022-3-18
移动:Rik 2023-6-23
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.

请先登录,再进行评论。


I
I 2022-3-21
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?

类别

Help CenterFile Exchange 中查找有关 Low-Level File I/O 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by