How to find average values inside a matrix
    2 vues (au cours des 30 derniers jours)
  
       Afficher commentaires plus anciens
    
    Trond Oesten
 le 13 Fév 2015
  
    
    
    
    
    Modifié(e) : Trond Oesten
 le 13 Fév 2015
            Hi,
I'm trying to find the average values inside a matrix, [N 1]. I'm using N simulations and for each simulation I get a value. What I want to do is to find the average value of G after each simulation of N and sample these results in a new matrix.
My script:
clc; clear all; close all;
N = 10;
x = 5;
G = zeros(N,1);
for i = 1:N;
     j = i*x; 
     G(i) = j; 
  end
Best regards
Trond Oesten
0 commentaires
Réponse acceptée
  Image Analyst
      
      
 le 13 Fév 2015
        There is no Monte Carlo concept at all in that script. Anyway, to find the mean value of G after each run of N iterations, just put this line after the loop:
meanG = mean(G);
If you want the means at the end of each i'th iteration, then put this inside the loop, just after you assign G:
meanG(i) = mean(G);
It just depends on where you want to take the mean.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
				En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

