How to access data from a struct when the dot notated reference is passed as a char array?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I have loaded some struct data into a container I'm calling 'CMData' in my function.
I want the function to access the array of data in 'CMData.Car_ax.data' which I'm passing in a char array to the function as an argument called 'signal'
I want to perform some other functions such as Standard Deviation, and some boundary value checks in which I want to iterate over the contents of the struct array but Matlab is doing this on the char array rather than the fields of struct CMData. For example, if I count the number of elements in 'signal' I get 18, which is the number of characters that make up 'CMData.Car_ax.data' when really I'm looking for a value of 3250.
How do I change this so that I am using a struct reference and not a char array?
1 Kommentar
Antworten (1)
prasanth s
am 11 Okt. 2019
To to get the field names of struct array, use 'fieldnames' function
S.x=1;
S.y=2;
fields = fieldnames(S)
then, to get the data from struct array, refer following code
data1 = S.(fields{1})
1 Kommentar
Stephen23
am 11 Okt. 2019
Siehe auch
Kategorien
Mehr zu Structures finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!