Borrar filtros
Borrar filtros

Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

Creating Loop using while

1 visualización (últimos 30 días)
James
James el 30 de Sept. de 2013
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
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

Respuestas (1)

Wayne King
Wayne King el 30 de Sept. de 2013
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 comentarios
Wayne King
Wayne King el 30 de Sept. de 2013
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 el 30 de Sept. de 2013
I dont know now its not running. Is there something i need to add

La pregunta está cerrada.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by