got confuse .. where is my mistake

what should i do to solve OR where is my mistake
function summa = eja(A)
summa = 0;
[r c] = size(A);
for i = 1:r
summa = summa + (sum(A(r>=c)));
end
end

Réponses (1)

Alan Stevens
Alan Stevens le 27 Sep 2020

0 votes

c is fixed as the last column. So in
[r c] = size(A);
for i = 1:r
summa = summa + (sum(A(r>=c)));
end
you are trying to sum the values of just those rows that are equal to or greater than the number of columns.

6 commentaires

Abdur Rob
Abdur Rob le 27 Sep 2020
yes sir ... but not working with this
Abdur Rob
Abdur Rob le 27 Sep 2020
Abdur Rob
Abdur Rob le 27 Sep 2020
sir have a look its giving this output
I would add:
When you write a function, in this case called halfsum, you should put the function name in the header line.
You called it eja. Instead, you want to do this:
function summa = halfsum(A)
And then name the m-file as halfsum.m. Things will get confusing and problematic otherwise.
Alan Stevens
Alan Stevens le 27 Sep 2020
Modifié(e) : Alan Stevens le 27 Sep 2020
@Abdur Rob Yes. That's what I said! I showed the lines that were giving the trouble. The following will do the sum you want:
function summa = eja(A)
summa = 0;
[r, c] = size(A);
for i = 1:r
summa = summa + sum(A(i,i:c));
end
end
Abdur Rob
Abdur Rob le 27 Sep 2020
thank you sir

Connectez-vous pour commenter.

Catégories

En savoir plus sur Startup and Shutdown dans Centre d'aide et File Exchange

Produits

Tags

Question posée :

le 27 Sep 2020

Commenté :

le 27 Sep 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by