Any alternative to using the eval command
Ältere Kommentare anzeigen
Hi,
Is there a way to execute the following command without using the eval command?
eval(['save ADCP', num2str(k), ' U V W']);
I want to save the variables U V W to a mat file called ADCPx where x is a number that changes in each iteration of a loop.
The above command works fine but I was wondering if there was an alternative way?
Thanks
5 Kommentare
Jan
am 23 Feb. 2018
"I want to save the variables U V W to a mat file called ADCPx where x is a number that changes in each iteration of a loop."
How do you get those numbers into the variable names in the first place?
You could easily avoid this whole issue by not adding numbers onto variable names. A number implies that you have a de-facto index, in which case why not just turn it into a real index, which would be simpler, more efficient, less buggy, and easier to debug. And you would avoid magically accessing variable names, wherever that might occur in your code.
Jan
am 23 Feb. 2018
@Stephen: ADCP1 is the name of the MAT-file, not a numbered variable. For files in the file system, indexing is not implemented by the modern operating systems, unfortunately. I loved Bill Gates' idea of omitting the complete file system stuff and replace it by a data base. Organizing files in folders is a stone age method. But, sigh, Mr. Gates decided to develop ribbons and tiles at first, while the file system still limits the length of the names to 260 characters.
Stephen23
am 23 Feb. 2018
@Jan Simon: I must have gone blind for a moment. You are quite right.
Guillaume
am 23 Feb. 2018
"Organizing files in folders is a stone age method"
Agreed! And using said folder organisation as an integral part of your programming language is even worse. Looking at you there, matlab with your @folder, +folder, private folder, etc.!
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Variables finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!