Build Matrix from Text file or String
Afficher commentaires plus anciens
Hey Guys, I'm working with Mathematica and MatLab and I just wrote a function, which translates the results (matrices and vectors) I get in Mathematica (saved as a .txt-file) into the syntax I'm using in my MatLab script. The output of this function is a char-array and I also save it as a .txt-file. Which looks like that:
'[1 2 3;4 5 6;7 8 9];'
And I want to have this as an actual asignment for the matrix-elements, so something like that:
A=[1 2 3;4 5 6;7 8 9];
Is there a way to convert this character array into an actual MatLab command to asign the matrix-elements?
4 commentaires
"I just wrote a function, which translates the results (matrices and vectors) I get in Mathematica (saved as a .txt-file) into the syntax I'm using in my MatLab script"
Trying to evaluate that string will be waste of your time and MATLAB's time. You would be much better off writing the data to a standard CSV file, so it looks like this:
1,2,3
4,5,6
7,8,9
And then simply importing that into MATLAB using csvread:
A = csvread(...);
Using any of the standard file input-output formats and functions will be a lot simpler, waste less time, and be more efficient than what you are trying to do.
Stephen23
le 3 Nov 2017
@Jakob: you are trying to use MATLAB as a parser, which is rarely efficient. It may be simpler to create those files to contain valid MATLAB code, and then just call the script.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Characters and Strings dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!