I want to use this code to subtract one value from each number in the histogram when all have been selected to find the new number with zero counts. This code worked (since there are two if loops with one nested) for the first two times 1 is subtracted from cdiff, but then returns the error 'Unbalanced or unexpected parenthesis or bracket.' : %check if Cdiff is empty:
if isempty(C_diff) fprintf('C_diff is empty (all numbers have drawn once) \n'); cdiff_counts= counts - 1;%cdiff_data_vector = reshape(data,[9,numel(data)]);
C_diff = find(cdiff_counts==0);%return vector of values with 0
fprintf('By subtracting 1 count for all numbers, the new C_diff is %d\n', C_diff); if isempty(C_diff) fprintf('C_diff is empty (all numbers have drawn once) \n'); cdiff_counts= cdiff_counts - 1;%cdiff_data_vector = reshape(data,[9,numel(data)]); C_diff = find(cdiff_counts==0);%return vector of values with 0 fprintf('By subtracting 1 count for all numbers, the new C_diff is %d\n', C_diff); endelse fprintf('C_diff is %d\n', C_diff);%
endReplacing the first 'if' with 'for' returns 'Unbalanced or unexpected parenthesis or bracket.'
How can I get this to occur until C_diff is no longer an empty array?
if isempty(C_diff) fprintf('C_diff is empty (all numbers have drawn once) \n'); cdiff_counts= counts - 1;%cdiff_data_vector = reshape(data,[9,numel(data)]); C_diff = find(cdiff_counts==0);%return vector of values with 0 fprintf('By subtracting 1 count for all numbers, the new C_diff is %d\n', C_diff); else fprintf('C_diff is %d\n', C_diff);% end
Best regards,
Alex
Best Answer