How to plot the sums of the columns in a matrix using a for loop?

I am trying to plot the column number of matrix J versus the sum of that column using a for loop. The size of the matrix is 201 by 201. The plot should look like a sine wave, but it is not coming out correctly. This is my code so far:
for i=1:201
A=sum(J(:,i));
B=i;
end
plot(B,A)

 Respuesta aceptada

for i=1:201
A(i)=sum(J(:,i));
B(i)=i;
end
plot(B,A)

1 comentario

Thank you very much! This has been bothering me for a while.

Iniciar sesión para comentar.

Más respuestas (1)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Preguntada:

A R
el 9 de Jun. de 2015

Editada:

el 9 de Jun. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by