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에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!