Hey all,
I'm new to MATLAB (and programming) and I have a question about how to call data stored in a structure array in a function. For a little bit of background, I have a bunch of related data stored in a scalar structure array I've named 'Data' with fields named f1, f2, f3 and so on that all contain 2×2 matrices.
To plot data from any of these fields seems simple enough, it's just (for example):
plot(Data.f1(:,1), Data.f1(:,2))
What I want to do now is create a function where the input(s) of the function dictate which of these fields are plotted. Thus, if the input variable of the function is x then the corresponding matrix to be plotted should be something like
plot(Data.f_x(:,1), Data.f_x(:,2))
However, when I try this is it obvious that MATLAB has no idea that x is supposed to be a variable. And the text in the function parenthesis isn't really a string (I guess) because I have tried using num2str() and sprintf() functions to try and get around this like
plot(Data.f_num2str(x)(:,1), Data.f_num2str(x)(:,2))
This just looks plain wrong to me, but I don't know enough to know why. Any help would be greatly appreciated.
Best Answer