Can anyone help me in this Matlab exercise

Asked

Viewed 96 times

0

inserir a descrição da imagem aqui inserir a descrição da imagem aqui

Someone can help me in this exercise Matlab. It’s Alinea B.

I did so but I could not understand why this is wrong. Could you explain to me why it is wrong?

function [i120, m120] = func11(mat)

i120 = 0;

m120 = 0;

for i = 1 : size(mat,1)

[ival,mval] = func10(mat(i,:),120)

i120 = i120 + 1;

m120 = m120 + 1;

end

From here on I can no longer finish the code, because I don’t see how I can implement the previous function.

1 answer

1

In this case, the statement requests that the previous function be used. Thus, the best way is to iterate through the lines. Generally, with MATLAB it is better to take advantage of the ability to use vectorization. Anyway, follow a possible solution as stated:

function [nIgualTotal, nMaiorTotal] = func11(mat)
     nLinhas = size(mat);
     nIgualTotal = 0;
     nMaiorTotal = 0;
     limite = 120;

     for i = 1:nLinhas(1)

         [nIgual, nMaior] = func10(mat(i,:), limite);

         nIgualTotal = nIgualTotal+nIgual;
         nMaiorTotal = nMaiorTotal+nMaior;
     end

end

Alternatively, the vector code could look something like:

function [nIgualTotal, nMaiorTotal] = func11(mat)

limite = 120;

nIgualTotal = numel(mat(mat == limite));

nMaiorTotal = numel(mat(mat > limite));


end

Browser other questions tagged

You are not signed in. Login or sign up in order to post.