getting a number from a text file

I have txt file with 1 number inside only, nothing else.
is there a way to get that number as a variable so that i can use an if statement on it, more specifically if an inputted number is greater than the number in the txt file.

7 Comments

Ok thank you, reading it as a matrix worked. But now is there a way for me to have the code change the number in that file after an action.
Hint to OP: Always read the "See Also" section of the documentation
I did read this, but what i need to do is edit the number i have in the text file, so what i did is:
C
R=readmatrix('CashReserve.txt');
"CashReserve" is the name of the txt file.
And what i need to do is be able to update this txt file (CR) after an action.
so is there a way to do that in code
filename = 'CashReserve.txt');
R = readmatrix(filename);
R = R - 1234.56;
writematrix(R, filename);

Sign in to comment.

Answers (0)

Products

Release

R2020a

Tags

Asked:

on 5 Dec 2021

Commented:

on 5 Dec 2021

Community Treasure Hunt

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

Start Hunting!