I have 100 models (matrices), where each matrix's size is 4X3. Each of the four variables R_L
, N_g
, N_Pc
, and uT
are of size 4x3x100, where 4X3 is size of each matrix and there are 100 of such matrix. I have attached a snapshot of two variables to give an idea of what I mean:
I am looping through matrix 1 of first three variables (i.e. R_L
, N_g
, N_Pc
) and comparing each element in matrix 1 of these variables with elements in other 99 matrices. I want to find those elements where all three variables in those 99 matrices are equal to corresponding three variables in any element of matrix 1.
For example, if all three variables in element (1,1) of matrix 1 have correspondingly similar values in element (2,2) of matrix 2, (2,1) of matrix 3, (2,4) of matrix 3 etc. then I will pick the results from variable 4 (i.e. uT
) at all those above element positions i.e. (1,1) of matrix 1, (2,2) of matrix 2, (2,1) of matrix 3, (2,4) of matrix 3 etc from uT
and store those results in a new variable called store_result
to plot its histogram. It is shown in code below.
nModel=100;
ixk=1;
% looping inside model # 1
for k_model1=size(R_L,1):-1:1
for i_model1=1:size(R_L,2)
% comparing values in model 1 to values in model 2 to nModel
for model_no=2:nModel
% looping inside each model from model # 2 to nModel
for k=size(R_L,1):-1:1
for i=1:size(R_L,2)
if ismember(R_L(k_model1,i_model1,1), R_L(k,i,model_no)) &&...
ismember(N_g(k_model1,i_model1,1), N_g(k,i,model_no)) &&...
ismember(N_Pc(k_model1,i_model1,1), N_Pc(k,i,model_no))
index_for_identical_results(:,:,model_no)=intersect(ismember(R_L(k_model1,i_model1,1), R_L(k,i,model_no)),...
ismember(N_g(k_model1,i_model1,1), N_g(k,i,model_no)),...
ismember(N_Pc(k_model1,i_model1,1), N_Pc(k,i,model_no)));
end
end
end
end
store_result(:,ixk)=uT(index_for_identical_results(:,:,model_no));
ixk=ixk+1;
end
end
I have following concerns that I would like to be addressed:
ismember
would be useful only when the values match exactly. In case there are no exact similar values, what would you suggest if I would like to give certain interval within which the values fall then it should be considered equal.Since I want to find a grid (element) where all three variables are equal, therefore the function
intersect
would not work here (even though I have used in the code above). What would you suggest to use instead ofintersect
which can perform the similar function with multiple variables.
Thanks.