Avoid for loop?
    4 vues (au cours des 30 derniers jours)
  
       Afficher commentaires plus anciens
    
    grega
      
 le 19 Déc 2018
  
    
    
    
    
    Réponse apportée : Stephen23
      
      
 le 19 Déc 2018
            I want to generate arbitrary matrix of indeces, e.g.:
1 2 3 4
2 3 4 5
3 4 5 6
4 5 6 7
5 6 7 8
6 7 8 9
One can observe a series in it. I solved the problem as follows:
% --- Inputs
x      = 1:9;
window = 4;
% --- creating the matrix
mm     = length(x);
nb_rws = mm - window + 1;
y      = ones(nb_rws,window);
for i = 1 : nb_rws
    y(i,:) = x(i : i + window -1);
end
y
Is there a solution to avoid the for loop? Thanks..
0 commentaires
Réponse acceptée
  madhan ravi
      
      
 le 19 Déc 2018
        
      Modifié(e) : madhan ravi
      
      
 le 19 Déc 2018
  
      y=hankel((1:4),(4:9))'
Gives:
y =
     1     2     3     4
     2     3     4     5
     3     4     5     6
     4     5     6     7
     5     6     7     8
     6     7     8     9 
0 commentaires
Plus de réponses (1)
  Stephen23
      
      
 le 19 Déc 2018
        Simpler:
>> hankel(1:6,6:9)
ans =
   1   2   3   4
   2   3   4   5
   3   4   5   6
   4   5   6   7
   5   6   7   8
   6   7   8   9
0 commentaires
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!


