MATLAB: Accept or Reject

acceptallowfunctionginputreject

I am trying to write a script that allows me to accept or reject data, so would ginput work for that?

Best Answer

Here is an example. I generate a random dataset, then I cycle through each subset of data and I enter an "A" for accepting the data OR a "R" to reject the data. At the end, a new dataset is created with only the accepted data.
data = rand(5,10); % generate 5 rows of random data
indices = 1:size(data,1); % initialize indices of data
figure;
for ii = 1 : size(data,1)
plot(data(ii,:));
[x,y,button] = ginput(1);
if button == 97 % A - for accept
disp('Input Accepted!');
elseif button == 114 % R - for reject
indices(ii) = 0;
disp('Input Rejected!');
else
disp('Button not recongnized!')
end
end
indices = indices(indices~=0); % Remove indices that were rejected
new_data = data(indices,:); % Create new dataset with only accepted data