Analyzing data using &&

1 次查看(过去 30 天)
Mukhtar Ahmed
Mukhtar Ahmed 2019-10-7
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]

回答(1 个)

Steven Lord
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?
  1 个评论
Mukhtar Ahmed
Mukhtar Ahmed 2019-10-7
Thank you Steven. That helps to understand. I want to know how many of the columns have data that satisfy the two criterion. For the first criterion if is self explanatory. The second condition I need is to add another filter data with peaks that have x times larger than the background standard deviation.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by