finding the mean and reducing the value
    4 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
    johnson saldanha
 il 19 Nov 2018
  
    
    
    
    
    Modificato: Andrei Bobrov
      
      
 il 19 Nov 2018
            suppose i have a matrix x=[ 0.01  0.02  0.034  0.045  0.054  0.06]
and y=[1 1 1 2 1 1]
i want the output to be x1=[0.021  0.045  0.057] and y1=[1 2 1]
the number of elements in x and y are the same. whenever a repeating digit is encountered in the matrix y, the mean of the values in x for the number of reapeted values should be calculated and shown in x1 and the repeated values should be reduced to a single value and shown in y1
0 Commenti
Risposta accettata
  Andrei Bobrov
      
      
 il 19 Nov 2018
        
      Modificato: Andrei Bobrov
      
      
 il 19 Nov 2018
  
      y = [1 1 1 2 1 1]';
x = [ 0.01  0.02  0.034  0.045  0.054  0.06]';
ii = [true;diff(y(:)) ~= 0];
x1 = accumarray(cumsum(ii),x,[],@mean);
y1 = y(ii);
0 Commenti
Più risposte (0)
Vedere anche
Categorie
				Scopri di più su Data Types in Help Center e File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

