How to Edit Imported Notepad Values and Save the New Values
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I want to import a row of data that looks like:
0.09 0.45 45 0 0.006 0.242 4.67 4 0.89925 1
Set them equal to variables in my GUI
Edit the variables
Save the new values over the old ones
Here is what I have:
[filename, path] = uigetfile('*.txt');
figure(app.UIFigure);
app.T = readtable(filename, 'Delimiter', 'space');
ct = app.T(:,1);
cr = app.T(:,2);
app.ctEditField.Value = table2array(ct);
app.crEditField.Value = table2array(cr);
(excluded the other 8 variable since it seems redunant)
Each value edit field has the same function
value = app.ctEditField.Value;
To edit the variables, I did this:
app.T.ct(1) = app.ctEditField.Value;
app.T.cr(1) = app.crEditField.Value;
Then I save them:
Q = table2array(app.T(:,:));
fileid = fopen('name.txt','w');
fprintf(fileid, '%6.5f\n' , Q);
This results in the following output in my text file where I am only changing the value for ct to 5. The original data is on top of the new data in a column. I do not have an error message to debug. How do I properly edit/save the data to only include the updated data as a row of numbers rather than a column of numbers?
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
0 Kommentare
Antworten (1)
Hornett
am 29 Sep. 2023
I understand you are facing problem while updating the already existing values in text file.
You can try using the "writematrix" function to write output data to text file.
Here is the sample code for “writematrix” usage:
M = magic(5)
writematrix(M,'mytxt.txt','Delimiter',' ')
For more detail you can refer to the following documentation page on writematrix function: https://www.mathworks.com/help/matlab/ref/writematrix.html
I hope this information resolves your query.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!