How to find multiple means of an array

2 visualizaciones (últimos 30 días)
Darrien Walters
Darrien Walters el 22 de Oct. de 2020
Comentada: Darrien Walters el 22 de Oct. de 2020
I have an array and I'm trying to make another array consisting of mean values of the first array.
I have some code i used to try and solve it myself using a for loop
A= (1:10);
b = 2;
c=1;
for i = 1:10
d(:,i) = mean(A(b:c));
b=b+1;
c=c+1;
end
Any suggestions or changes would be much appreciarted as this code currently doesn't work.
  1 comentario
Darrien Walters
Darrien Walters el 22 de Oct. de 2020
For anyone wondering i figured out my issue. this code is fine for what i needed it to do

Iniciar sesión para comentar.

Respuesta aceptada

Image Analyst
Image Analyst el 22 de Oct. de 2020
Yes, A(b:c) is A(2 : 1) which is null since your starting index, 2, is after your ending index, 1. So that's why it didn't work.
  1 comentario
Darrien Walters
Darrien Walters el 22 de Oct. de 2020
Yes thanks alot not sure how that slipped past me

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by