Analyzing data using &&
13 views (last 30 days)
Show older comments
I am trying to analyze my data that meet two conditions. This seems simple but I keep stumbling on this error:
Operands to the || and && operators must be convertible to logical scalar values.
Error in ROI_test2 (line 28)
Here is the code I am using:
%%Load data
data_test = load('test.txt');
[n_x n_y] = size(data_test);
df_data = diff (data_test);
counter = 0;
diff_data=NaN(n_x-1,n_y);
var_data=NaN(n_x-1,n_y);
%% Process raw data to find first derivative and moving variance
for i = 1:n_y
trace_data = data_test(:,i);
diff_data(:,i) = diff(trace_data);
figure (1)
subplot(3,1,1)
plot(trace_data)
subplot(3,1,2)
plot(diff_data(:,i))
subplot(3,1,3)
var_data(:,i) = movvar(diff_data(:,i),5);
plot(var_data(:,i));
title(i)
thresh_pos = max(diff_data(:,i));
thresh_neg = min(diff_data(:,i));
stdvar = std (var_data);
if abs(thresh_neg) >= 0.35*thresh_pos && var_data > 6*stdvar
%pause
counter = counter +1;
particles_identified(:,counter) = i;
end
end
%% Display the number of positive events
disp(length(particles_identified))
[SL: edited to format the code as code and to smart indent it]
0 Comments
Answers (1)
Steven Lord
on 7 Oct 2019
Your variables thresh_neg and thresh_pos are the min or max respectively of a vector of data and so are scalars. This means the result of abs(thresh_neg) >= 0.35*thresh_pos is a logical scalar.
Your variable var_data is a non-vector as soon as i = 2, and so the result of var_data > 6*stdvar is also a matrix. That's why you receive that error.
What do you want to do with your particle identification if statement in that case?
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!