Exporting Edited Data to Notepad in Appdesigner

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 件のコメント

I
I 2022 年 3 月 15 日
移動済み: Rik 2023 年 6 月 23 日
Opening the textfile with the row of data:
app.T = readtable(filename, 'Delimiter', 'space');
Error using readtable (line 245)
"filename" must be a string scalar or character vector.
Editting the numbers:
app.T.ct(1) = app.ctEditField.Value;
Saving the new values:
Q = app.T{:,1};
fileid = fopen('name.txt');
fprintf(fileid, '%f\n' , Q);
fclose(fileid);
I am still getting an error with this process. I think it must be how the numbers are represented. There is also a chance that I may not be editting the numbers correctly.
Stephen23
Stephen23 2022 年 3 月 21 日
Rather than READTABLE you can probably use READMATRIX.
And then use WRITEMATRIX.
I
I 2022 年 3 月 23 日
I tried to use writematrix and I was told that I have too many input arguments. I am not sure how to handle that.
My current issue is now between editing and exporting the data.
I would like to replace my row of data which looks like: 0.09 0.45 45 0 0.006 0.242 4.67 4 0.89925 1
I would like the data to still appear as a row with one space in between each number.
My current problem is that the edit button is adding the data below the original data and all of the data is appearing as a column with one space in between each number.
I would like to remove the old data and only retain the edited new data.
In this example below, I have replaced 0.09 with 5.
My current output appears as the following:
0.09000
0.45000
45.00000
0.00000
0.00600
0.24200
4.67000
4.00000
0.89925
1.00000
5.00000
0.45000
45.00000
0.00000
0.00600
0.24200
4.67000
4.00000
0.89925
1.00000
Here is how the code for editing the data looks. Every entry is roughly the same.
app.T.ct(1) = app.ctEditField.Value;
app.T.cr(1) = app.crEditField.Value;
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 日

0 投票

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 件のコメント

I
I 2022 年 3 月 13 日
移動済み: Rik 2023 年 6 月 23 日
Q = (app.T(:,:));
fileid = fopen('name.txt,'w');
fprintf(fileid, '%6.2f\n' , Q);
I am getting an error with data_to_write.
Am I using this incorrectly or could it be the type of data that I am trying to save?
Unrecognized function or variable 'data_to_write'.
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 日

0 投票

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?

製品

リリース

R2020b

質問済み:

I
I
2022 年 3 月 11 日

移動済み:

Rik
2023 年 6 月 23 日

Community Treasure Hunt

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

Start Hunting!

Translated by