필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

how to translate this macro

조회 수: 2 (최근 30일)
marianoc84
marianoc84 2012년 1월 2일
마감: MATLAB Answer Bot 2021년 8월 20일
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
Titus Edelhofer
Titus Edelhofer 2012년 1월 2일
Hi, what do you mean by "every environment"? Second, there is a "(" missing somewhere in your macro ...
Titus
marianoc84
marianoc84 2012년 1월 2일
Every environment doesn't means nothin special, I just need to report that code in a sort of pseudo code readeable even to a person who doesn't know matlab.
Yes, I was miss the first (, this is correct now. :)

답변 (1개)

Friedrich
Friedrich 2012년 1월 2일
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
Walter Roberson
Walter Roberson 2012년 1월 2일
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.

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by