How can I do the average between many vector columns?
22 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Adrian
el 16 de Abr. de 2014
Comentada: Umesh Gautam
el 7 de Nov. de 2023
I have 120 1x500 vector columns, so I can't do it manually. For example, I have the following vector columns, each 1x500 in size:
a1, a2, ......, an, where n=120
I want to do:
(a1 + a2 + ... + an)/n
Thank you very much!
Adrian
0 comentarios
Respuesta aceptada
José-Luis
el 16 de Abr. de 2014
Editada: José-Luis
el 16 de Abr. de 2014
%Creating vectors:
for ii = 1:50
str = ['a' num2str(ii)];
assignin('base',str,rand(100,1));
end
%Preallocating:
your_mat = ones(100,50);
%Putting everything together, this is the part you want if you already have the vectors
for ii = 1:50
str = ['a' num2str(ii)];
your_mat(:,ii) = evalin('base',str);
end
your_val = mean(your_mat(:));
Please accept an answer if it helps you.
2 comentarios
lvn
el 17 de Abr. de 2014
Replace the last line of Jose-Luis code with
your_val = mean(your_mat);
Then you will have what you want. However, much better would be to initially read in/or store your data in a matrix, rather than in separate vectors, then you can simply use what Azzi wrote.
Más respuestas (1)
Azzi Abdelmalek
el 16 de Abr. de 2014
mean(A)
2 comentarios
Umesh Gautam
el 7 de Nov. de 2023
@Azzi Abdelmalek Thanks...this is a simple solution and it works well.
Ver también
Categorías
Más información sobre Graphics Object Properties en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!