Effacer les filtres
Effacer les filtres

how to convert text file as it was written .m file to call functions?

2 vues (au cours des 30 derniers jours)
I have bunch of function orders written in text file.
For example text file contains
"move(4,5)
degrade(3)
plussum(6,7)"
and those are supposed to be function name and variables.
I want matlab to read that text file as it was written im .m file to call functions with variables

Réponse acceptée

Walter Roberson
Walter Roberson le 22 Avr 2024
SS = fileread(NAME_OF_FILE);
eval(SS)

Plus de réponses (1)

Steven Lord
Steven Lord le 22 Avr 2024
If all the text in the file consists of valid MATLAB code and comments, just change the extension from .txt to .m.
  1 commentaire
Melih Furkan SEN
Melih Furkan SEN le 25 Avr 2024
Thats not what I meant to ask.
some part of code will change depending of user requires.
If user wants txt file named "A.txt" to run, I want code to copy the txt strings into certain (for example 70th line of main code) and use that "A.txt" as it was line of code

Connectez-vous pour commenter.

Tags

Produits


Version

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by