From: Ahmed on 7 Jul 2010 14:18 There is a label above this text area which says "Your message is restricted to plain text", therefore my code will be messy: <<CODE STARTS HERE>> % Circuit constants C1 = 10 * 10^(-9); C2 = 330 * 10^(-9); R = 10 * 10 ^ 3; w = 2 * pi * 50; % Simulation time limit TMAX = 0.1; % Simulation time resolution TRES = 0.0001; for ti = 1 : 1 : TMAX / TRES % tt: integer time index to use in vectors % t : actual time value t = ti * TRES; % Intermediate variables that simplifies the expression k4 = C1 / (R * R * C2 * C2); an = R * R * R * R * C2 * C2 * C2 * C2 * w; bn = R * R * C1 * C2 * C2; abd = R * R * R * R * C2 * C2 * C2 * C2 * w * w + C1 * C1; c = C1 * C1 * C1 / (R * R * R * R * R * R * C2 * C2 * C2 * C2 * C2 * w + R * R * C1 * C1 * C2); fi = C1 / (R * R * C2 * C2 * 2); % Calculate current sample i(ti) = c * exp(-k4 * t) + (sqrt(an * an + bn * bn) / abd) * cos(w * t + atan(fi)); % Calculate voltage sample v(ti) = R * i(ti); end % Index for plotting tt = 1 : 1 : TMAX / TRES; % Truncate workspace variables tt = tt(1 : TMAX / TRES); i = i(1 : TMAX / TRES); v = v(1 : TMAX / TRES); % Plot current plot(tt, i); <<CODE FINISHES HERE>> With the code above, I plot the variable "i" successfully. The horizontal axis of the graph is supposed to display 'time' value (t). But time value is not integer, so I wasn't able to use it as array indexes. Instead I used an integer index "ti". However, this "ti" array does not contain the actual time intervals; I mean each sample of it corresponds to "TRES" amount of seconds. Therefore, when I try to plot the array "i", the horizontal axis values are 1/TRES times higher than their actual values. How do I scale horizontal axis numbers?
|
Pages: 1 Prev: Zero elements in sparse matrix Next: Multcompare HELP!!! |