Вопрос

I have the data as shown in below:

    for a=1:2
    for b=1:2
        for c=1:2
            for d=1:2
                 m{a,b}{c,d}=zeros(3,3);
            end
        end
    end
end

m{1,1}{1,1}=[6 1 4;3 7 2;1 5 6]; %pass
m{1,1}{1,2}=[3 5 4;9 2 7;5 5 6];
m{1,1}{2,1}=[5 2 3;5 9 5;2 2 3];
m{1,1}{2,2}=[2 1 0;3 5 6;8 8 8];

m{1,2}{1,1}=[2 1 3;5 6 7;3 5 5];
m{1,2}{1,2}=[6 2 4;7 7 9;3 5 8];%pass
m{1,2}{2,1}=[1 2 2;4 5 5;2 6 7];
m{1,2}{2,2}=[3 3 1;2 4 5;6 7 5];

m{2,1}{1,1}=[2 5 0;3 7 6;8 6 8];
m{2,1}{1,2}=[3 6 4;3 2 7;5 8 6];
m{2,1}{2,1}=[3 9 1;2 1 5;6 2 8];
m{2,1}{2,2}=[9 1 4;9 7 7;5 2 8];%pass

m{2,2}{1,1}=[0 5 0;3 2 6;8 6 9];
m{2,2}{1,2}=[1 2 7;5 2 5;4 2 6];
m{2,2}{2,1}=[2 1 3;2 4 6;6 9 5];
m{2,2}{2,2}=[3 7 1;1 4 5;6 9 3];

I would like to take the diagonal of each set of data and check whether all these numbers are larger than five .

For instance, the diagonal for m{1,1}{1,1} is 6,7,and 6 respectively which larger than five,thus it fullfill the condition.

Moreover,I need to know the position of dataset which pass the condition.In this example, the result of dataset m{1,1}{1,1} ,m{1,2}{1,2} and m{2,1}{2,2} are pass.

Это было полезно?

Решение 2

   a=cellfun(@(x) cellfun(@(y) all(diag(y)>5),x),m,'uniformoutput',false)

you can find the answer inside a :)

Другие советы

t=cellfun(@(mii) cellfun(@(mjj) all(diag(mjj)>5),mii),m,'uni',false);

t = 
    [2x2 logical]    [2x2 logical]
    [2x2 logical]    [2x2 logical]

t{1,1} =
     1     0
     0     0

so m{1,1}{1,1} is true, m{1,1}{1,2} is false, etc

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top