Effacer les filtres
Effacer les filtres

MATLAB Function Output problem?

2 vues (au cours des 30 derniers jours)
Steve
Steve le 31 Déc 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!!!

Réponse acceptée

Chandra Kurniawan
Chandra Kurniawan le 31 Déc 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 commentaire
Steve
Steve le 31 Déc 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!!!!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by