MATLAB: Populating a matrix with values of the same index of two separately met conditions

arraysMATLABmatricesscientific computing

Hi All, So the problem I'm trying to solve is where I have a series of variable matrices (all same length, time stamped based on matching index) and I'd like to make a new matrix (or more than one) where a, b conditions are met in a, b matrices, respectively. Such that I'm left with the time matrix of the elements of the arrays that meet a or b conditions (not and) or below:
time = 1:100;
var1 = rand(1:length(time));
var2 = rand(1:length(time));
var3 = rand(1:length(time));
var4 = var3(var2 >= 1 "or" var1 >= 1);
newtime = time(var2 >=1 "or" var1 >= 1);
I need these such that I can plot values that meet these conditions on a time series where values that meet the conditions are one color and values that do not meet the condition fill in the remainder of the values to illustrate the differences between them. I have the part where the conditions are not met, I just can't lose values because some meet one condition but not the other. Thanks! Jack

Best Answer

var4 = var3(var2 >= 1 | var1 >= 1);
newtime = time(var2 >=1 | var1 >= 1);