How do I run an array through a loop and store the results?
Ältere Kommentare anzeigen
I am trying to run a loop element by element and then store the results as elements in a different array.
I can make it work if I use a scalar as the input but I want to run 10 scalars through the loop and store the results as an array.
Really don't know how to do it despite working at it for hours now.
Here is the code as it is now
clc;
clear;
k=1;
x=linspace(0,(pi/2),10);
sum=zeros(1,10);
while k<10 && abs((-1)^(k-1)*(x^(2*(k-1)))/factorial(2*(k-1)))>0.001
s=x(kidx);
sum = sum + (-1)^(k-1)*(x^(2*(k-1)))/factorial(2*(k-1));
k=k+1;
disp(sum)
end
end
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!