mardi 4 septembre 2018

| Matrix/Vector | if statement/loop | Couting without sum function

I wish to make statement that works without using sum function in matlab, I have already creates on working to find ratio from given matrix like below and find ratio that is over certain values.

For example I wish to find all ratio that is over 20 in each column. Where the input matrix is something like below

Ma = [0  5  1  5  22 ; 
     32 2  4  7  22 ; 
     10 10 10 10 20];

I wish the output would be this: [1/size(Ma,1) 0/size(Ma,1) 0/size(Ma,1) 0/size(Ma,1) 3/size(Ma,1) It would give output as values instead of size(Ma,1) but this way my function would work for any size columns.

function Ratio = ratio2(Ma)

[a, b] = size(Ma)
c = []


for h = 1:a
    for j = 1:b %Not sure if this correct if you I want to check if there is next columns 
    if Ma(a) >= 30
        c = c + 1;

    end

Ratio = c/size(Ma,1)

end

Main question is how implemented the second element where it check every rows instead of just one? For example if it over 20 it will +1 to the first column for vector/array c and then function will check the next column and then final Ratio is just divide every column in vector C by Size of the matrix (size(Ma,1))

Aucun commentaire:

Enregistrer un commentaire