필터 지우기
필터 지우기

Info

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

Creating Loop using while

조회 수: 1 (최근 30일)
James
James 2013년 9월 30일
마감: MATLAB Answer Bot 2021년 8월 20일
function [r] = func(~)
r = 10000;
m = 3;
while (m ~=0);
r = (10^(-m)*r);
m = m - 1;
end
I keep getting an error stating that m is undefined and not sure why

답변 (1개)

Wayne King
Wayne King 2013년 9월 30일
I have no trouble saving the M-file func.m in a folder on the MATLAB path, then executing
>> r = func
which returns 0.01
You don't need the ~ by the way
function r = func
r = 10000;
m = 3;
while (m ~=0);
r = (10^(-m)*r);
m = m - 1;
end
How are you trying to call the function?
  댓글 수: 3
Wayne King
Wayne King 2013년 9월 30일
That can't be what the above returns, the above returns 10000. In the code above you have m=1, then you have while m~=1 so the while loop never executes and the answer is simply what you have declared r to be which is 10^4.
James
James 2013년 9월 30일
I dont know now its not running. Is there something i need to add

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by