Execute text files in matlab

4 Ansichten (letzte 30 Tage)
Chloe Choi
Chloe Choi am 30 Nov. 2018
Bearbeitet: per isakson am 1 Dez. 2018
My text files look like:
a = [1, 2, 3, 4, 5]
b = [6, 7, 8, 9, 10]
I want to basically run my text files as if they’re just .m files, and use the variables defined in the text files.
Or is there a way I could just import the variables from these text files?
  2 Kommentare
per isakson
per isakson am 30 Nov. 2018
Why not use the extension .m ?
Walter Roberson
Walter Roberson am 1 Dez. 2018

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Mark Sherstan
Mark Sherstan am 30 Nov. 2018
Make a text file that looks like this and call it "test.txt":
1, 2, 3, 4, 5
6, 7, 8, 9, 10
Use the following function to load it into MATLAB
load test.txt
Then seperate out your data into its variables:
a = test(1,:);
b = test(2,:);

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by