Goto command in matlab: Undefined function 'goto' for input arguments of type 'double'"

3 ビュー (過去 30 日間)
jeffin
jeffin 2014 年 9 月 25 日
編集済み: Stephen23 2015 年 6 月 30 日
I am in need of using goto command in matlab. I came to know that there is no goto command in matlab. But there are programs that run using goto command (got from net) where i am getting the output.
Example 1
a = 5;
a = a - 1;
disp(a)
if a > 0
goto(4)
return
end
Example 2
a = 5;
if a == 5
goto(9)
return
else
goto(12)
return
end
disp('a equals five')
goto(13)
return
disp('a does not equal five')
For Example 1 and 2 i'm able to get the output. But when i am using in my program goto(170) i am getting an error "Undefined function 'goto' for input arguments of type 'double'".
Can somebody help me. Thanks in ADVANCE...!
  9 件のコメント
José-Luis
José-Luis 2014 年 9 月 25 日
I recently had to modify some FORTRAN code that used goto and I am still reeling from the experience. Spaghetti code is an apt name.
There are cases where its use is justified, for instance to escape from nested loops. Using a goto will make for much cleaner code than setting flags all over the place. However the goto construct the OP mentioned is not native Matlab.
jeffin
jeffin 2014 年 9 月 25 日
編集済み: jeffin 2014 年 9 月 25 日
Thanks to all the authors who responded me well. @Kelly Kearney , @Stephen Cobeldick, @José-Luis , @Iain , @Sean de Wolski. i was able to slove the problem without goto function.

サインインしてコメントする。

採用された回答

Sean de Wolski
Sean de Wolski 2014 年 9 月 25 日
MATLAB does not have a goto function. Use regular functions instead.
  1 件のコメント
jeffin
jeffin 2014 年 9 月 25 日
I am using matlab R2013a. the link is not opening. Is there any other way...

サインインしてコメントする。

その他の回答 (1 件)

Iain
Iain 2014 年 9 月 25 日
Ok, so you've downloaded a function "goto" from the file exchange, and it's probably just using "eval" on every line from the one you tell it, to the end of the function. (This is an orgy of bad programming practice.)
To use it, you need to make sure that the goto.m (or goto.p) file is on your matlab path:
addpath('C:\This is where I keep bad m files\')

カテゴリ

Help Center および File ExchangeEntering Commands についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by