Analyzing data using &&
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Steven Lord
2019-10-7
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?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!