Help figuring out this Function file
Afficher commentaires plus anciens
This isnt HW, its a review for my final exam. I thought I had figured it out until I put in my own values and that just threw away my theory. Help please
- function [ y ] = mysum2( x,a,b )
- sum=0;
- for k=1:length(x)
- if a<=x(k)<=b
- sum = sum+x(k);
- end
- end
- y=sum;
- end
plug in array b b=[4 14 6 3 4 10 8 6]
y=mysum(b,-5,0) y=0
y=mysum(b,1,3) y=55
y=mysum(b,6,7) y=55
y=mysum(b,60,70) y=55
plug in array c=[3 -2 4 4 5 1 -4 -2 7] y=mysum(c,-10,-6) y=0
y=mysum(c,-2,0) y=-4
y=mysum(c,-2,-2) y=16
y=mysum(c,6,7) y=16
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Dates and Time dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!