Extract variables from a text data and add them to an array to plot a graph
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Hi all,
how do I extract the values from a a text data( see below), and add them into 2 arrays so that I could plot a graph?
the text data looks like this for eg.
distance=10
time=1
distance=20
time=2
distance=32
time=3
distance=45
time=4
.
.
.
I want to creat an array for distance and another array for time, and later plot a graph. can someone help me please?
Many thanks,
Alvin
0 Commenti
Risposte (1)
Julius Muschaweck
il 4 Mag 2021
Your example input is attached as SomeNameValueList.txt.
Calling
rv = ReadNameValueList('SomeNameValueList.txt')
plot(rv.distance, rv.time);
gives you a struct rv with, in this example, fields distance and time:
rv =
struct with fields:
distance: [10 20 32 45]
time: [1 2 3 4]
which you can plot to get
The function just reads these lines sequentially and appends the arrays in the same name fields in the rv.
If you had different input like
hopp=42
hopp=44
topp=32
hopp=21
pi=3.1415
# some comment, ignored
; another comment, ignored
you would get
rv =
struct with fields:
hopp: [42 44 21]
topp: 32
pi: 3.1415
0 Commenti
Vedere anche
Categorie
Scopri di più su Statistics and Machine Learning Toolbox in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!