Clear Filters
Clear Filters

MATLAB Function Output problem?

2 views (last 30 days)
Steve
Steve on 31 Dec 2011
Hello Experts,
I have the following function:
function X = STK(U, D, n, delta_t)
X = zeros(1,n); % Creating the vector of X
X(1) = 1; % = X(0) = 1;
r = randn(1,n); %
N = zeros(1);
for i=1:n
X(i+1) = X(i) - U*X(i)*delta_t + D*sqrt(delta_t)*r(i);
N(i) = i;
end
plot(N,X(1:n));
end
The function outputs the whole vector, I need it to output only the plot without any other ans = ... Please teach me how to do it, I mean to "enable/disable" output printing.
Happy New Year, Thanks a lot in advance!!!

Accepted Answer

Chandra Kurniawan
Chandra Kurniawan on 31 Dec 2011
function STK(U, D, n, delta_t)
X = zeros(1,n); % Creating the vector of X
X(1) = 1; % = X(0) = 1;
r = randn(1,n); %
N = zeros(1);
for i=1:n
X(i+1) = X(i) - U*X(i)*delta_t + D*sqrt(delta_t)*r(i);
N(i) = i;
end
plot(N,X(1:n));
end
  1 Comment
Steve
Steve on 31 Dec 2011
Thanks Chandra!!! Happy New Year, it may be funny but I have done something like a min before you answered and it really works.
It's like to write void in C/C++.
Thanks a lot, Happy New Year!!!!

Sign in to comment.

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!