Recording vectors in for loop, when the loop is running in a range starting with negative numbers
1 view (last 30 days)
Show older comments
I'm trying to record values of cn during a for loop, but I can't seem to index into a vector x using the value for the iteration, because my for loop is running from values -50:50. So It cant index into x at x(1,n). I have no idea how to solve this. Does anyone have any suggestions? Thank you!
clear; clc, clf;
t = 0:0.01:20;
A=2;
T=5;
wo = 2*pi()/T;
nmax = 50;
x = zeros(1,length(-nmax : 1 : nmax));
for n = -nmax : 1 : nmax;
if n ~=0
cn = (A/ (T*-1i*n*wo) ) * (exp(-1i*n*wo*T/2)-1);
else
cn = A/2;
end
x(1,n) = cn;
end
0 Comments
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!