1

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:

enter image description here

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:

  1. 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.

  2. 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 of intersect which can perform the similar function with multiple variables.

Thanks.

4

1 回答 1

1

我能够解决以下问题:

error=0.1;
ixk=1;
% looping inside model # 1
for k_model1=size(R_L,1):-1:1
    for i_model1=1:size(R_L,2)
        count=1;

        % 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 abs((R_L(k_model1,i_model1,1)-R_L(k,i,model_no))/R_L(k_model1,i_model1,1))<=error...
                            && abs((N_g(k_model1,i_model1,1)-N_g(k,i,model_no))/N_g(k_model1,i_model1,1))<=error &&...
                            abs((N_Pc(k_model1,i_model1,1)-N_Pc(k,i,model_no))/N_Pc(k_model1,i_model1,1))<=error
                        %                         index_for_identical_results(:,:,model_no)=
                        if count==1 && ixk==1
                            store_result(1:2,ixk)=vertcat(uT_mpersec_end_of_window(k_model1,i_model1,1),uT_mpersec_end_of_window(k,i,model_no));
                            count=count+2;
                        elseif count==1 && ixk~=1
                            store_result(1:2,ixk)=vertcat(uT_mpersec_end_of_window(k_model1,i_model1,1),uT_mpersec_end_of_window(k,i,model_no));
                            count=count+2;
                        else
                            store_result(count,ixk)=uT_mpersec_end_of_window(k,i,model_no);
                            count=count+1;
                        end
                    end
                end
            end
        end
        ixk=ixk+1;
    end
end
于 2012-02-09T05:49:02.907 回答