Using a variable in a function before it is defined.

조회 수: 12 (최근 30일)
Isaac Hargrave
Isaac Hargrave 2020년 3월 22일
답변: Image Analyst 2020년 3월 22일
I'm trying to create variables defined as the operations they perform at the specific iteration in the for loop; however, I am unsure how to define them before the iteration (i) is used.

답변 (1개)

Image Analyst
Image Analyst 2020년 3월 22일
Why do you think it should know what "i" is at that point in your code? You never said what i is, so it's undefined.
I think you want something like
fpbackward = y(2:end) - y(1:end-1)/h;
(but I don't think you even want that, but whatever...that's what you wrote). That will take the prior elements and divide them by the scalar h and subtract them from the latter elements.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by