plot data in from structure of data points with limits
1 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Object Programming 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!