how to velocize it (vectorizing)
    4 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
a=magic(10)
b=[4;5;9;2;3;4;2;7;4;9]  %width(a) element
x=ones(size(a));
for i=1:numel(b)
    x(1:max(b(i)-1,1),i)=0
end
0 Commenti
Risposte (1)
  Bruno Luong
      
      
 il 20 Ago 2023
        
      Modificato: Bruno Luong
      
      
 il 20 Ago 2023
  
      I don't know why a is matter beside that the first dimension is 10
a=magic(10);
b=[4;5;9;2;3;4;2;7;4;9];  %width(a) element
h = size(a,1);
x = double(ndgrid(1:h,b)>=b(:)')
;
9 Commenti
  Bruno Luong
      
      
 il 20 Ago 2023
				
      Modificato: Bruno Luong
      
      
 il 20 Ago 2023
  
			"I've noticed dramatic improvements when it comes to vectorizing code where there is a loop inside another"
Not really. The speed depens what you do in the body of the loop(s), not loop are nested or not.
I know what I'm talking on speeding MATLAB code.
Vedere anche
Categorie
				Scopri di più su Loops and Conditional Statements 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!

