Concatenating data from structure array for plotting

12 views (last 30 days)
I have a structure array with several levels of depth that I am trying to extract a specific set of data from in order to plot it. The plan is to draw individual elements from several different fields, and then combine them into a single array for plotting. I know that normally structures can be concatenated using [], but it doesn't seem to be working for this instance.
plot(x_values,[files([files.Param] == condition).Zone(1).Values(1,4)]);
Expected one output from a curly brace or dot indexing expression, but there were multiple results.
I know that the inner conditional statement is working, as I can extract it and get the appropriate logic matrix, but that means that I am looking at multiple elements of 'files' (which is exactly what I want to do), but they do not seem to be concatenating properly. Any suggestions would be appreciated.

Accepted Answer

Stephen23
Stephen23 on 8 Jan 2019
Edited: Stephen23 on 8 Jan 2019
  9 Comments
Stephen23
Stephen23 on 9 Jan 2019
Edited: Stephen23 on 9 Jan 2019
As I mentioned earlier, working with nested functions is not much fun.
You could try something like this:
fun = @(s) s.Zone(1).Values(1,4);
V = arrayfun(fun,files([files.Param]==condition))
Bob Thompson
Bob Thompson on 9 Jan 2019
Edited: Bob Thompson on 9 Jan 2019
That should be sufficient for this, thanks.
And in the future I know better how to avoid this whole situation, so double thanks.

Sign in to comment.

More Answers (1)

Mehmet Burak Ekinci
Mehmet Burak Ekinci on 18 Aug 2022
You may use custom matlab functions from file exchange to get values from nested struct arrays
See Answer in link for example.

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!