plot data in from structure of data points with limits

1 vue (au cours des 30 derniers jours)
Kevin Holst
Kevin Holst le 16 Mar 2012
I have a structure of datapoints, each of which is a structure of variables. I have created a simple function that will do a scatter plot all of a given x and y variable for each datapoint (see below). I would like to be able to provide a limiting variable so that not necessarily all of the data points will be plotted (ie, plot x vs y where z<10). The syntax that I'm pictureing is something like plot_data(array,'x','y','z','<10') but I'm not sure how to implement this.
function plot_data(array,xVar,yVar,varargin)
% Plots data from datapoints or datapoints_onesweep array
%
% Inputs:
% array = datapoint array to plot from
% xVar = x-variable for plot
% yVar = y-variable for plot
if nargin > 3
limitVar = varargin{1};
limitVal = varargin{2};
end
f = fieldnames(array);
d = cell(0);
x = [];
y = [];
for i = 1:length(f)
if strcmpi(f{i}(1),'D') && strcmpi(f{i}(2),'P')
d = [d f{i}];
x = [x array.(f{i}).(xVar)];
y = [y array.(f{i}).(yVar)];
end
end
h = scatter(x,y);
I know that I can add:
eval(['array.(f{1}).(limitVar)' limitVal])
to my if statement, but I'd like to avoid using eval if at all possible. Any ideas?

Réponses (0)

Catégories

En savoir plus sur Structures dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by