Rewritting to if-statement loop ?
    2 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
    Zaakir  Essop
 il 27 Apr 2016
  
    
    
    
    
    Risposto: Walter Roberson
      
      
 il 27 Apr 2016
            Hi
I have the following code and was wondering if anyone can help me rewrite it using an if loop
ShearForce = zeros(size(PositionsForce));                         %size of shear force matrix
BendingMoment = ShearForce;
for count = 1:1:size(PointLoads,1)
      ShearForce = ShearForce + PointLoads(count,1).*(PositionsForce<=PointLoads(count,2));   %ShearForce due to PointLoads
end
for count = 1:1:size(DistributedLoads,1)                            %ShearForce due to DistributedLoads
  ShearForce = ShearForce + DistributedLoads(count,1).*(max(DistributedLoads(count,2:3)) - min(DistributedLoads(count,2:3))).*(PositionsForce<min(DistributedLoads(count,2:3)));
  ShearForce = ShearForce + DistributedLoads(count,1).*(max(DistributedLoads(count,2:3)) - PositionsForce).*(and(PositionsForce>=min(DistributedLoads(count,2:3)),PositionsForce<=max(DistributedLoads(count,2:3))));
end
for count = (size(ShearForce,2)-1):-1:1
  BendingMoment(1:count) = BendingMoment(1:count) + 0.5.*(PositionsForce(count+1)-PositionsForce(count)).*(ShearForce(count+1)+ShearForce(count));
end
end
Any help would be appreciated.
0 Commenti
Risposta accettata
  Walter Roberson
      
      
 il 27 Apr 2016
        MATLAB does not have any "if loop", and I am not aware of any computer language that does.
"for" loops have their body repeated a fixed number of times.
"while" loops repeat their body until a condition becomes false, testing the condition first.
"until" loops repeat their body until a condition becomes true, doing the body once before first testing the condition. MATLAB does not implement "until", but it can be simulated using "while true" and testing the condition at the end with "break" if it is met.
"if" executes the body zero times (if the condition is false) or one time (if the condition is true.) "if" does not loop.
0 Commenti
Più risposte (0)
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!

