Info
Cette question est clôturée. Rouvrir pour modifier ou répondre.
how to translate this macro
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have this "macro"
err = (dd_y(x1:x2)'-yi(1:end)).^2
I would translate this into normal code runnable in every environment, not only Matlab. What can I do?
2 commentaires
Titus Edelhofer
le 2 Jan 2012
Hi, what do you mean by "every environment"? Second, there is a "(" missing somewhere in your macro ...
Titus
Réponses (1)
Friedrich
le 2 Jan 2012
Hi,
in general some pseudo code which can be run anywhere would be
for(i=0;i<=x2-x1;i++)
err[i] = (dd_y[i+x1] - yi[i])*(dd_y[i+x1] - yi[i])
The correct syntax and data types depending on the programming language you like to use. In addition make sure that dd_y(x1:x2) has the same amount of elements as yi which you like to access to avoid Index Out Of Bounds Exceptions / Segmentation Violation.
1 commentaire
Walter Roberson
le 2 Jan 2012
I would not call that pseudo-code, I would call that C code. Understanding it properly requires knowledge of C's trinary looping construct.
Closer to pseudo-code would be
i = 0;
while i <= x2 - x1 {
err[i] = (dd_y[i+x1] - yi[i]) * (dd_y[i+x1] - yi[i]);
i = i + 1;
}
However, both this version and your version would have problems if dd_y could contain complex numbers, as the original code uses the conjugate transpose rather than the plain transpose.
Cette question est clôturée.
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!