I have this function but whenever I call it using its name, I get an error
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Tariq Hammoudeh
el 30 de Dic. de 2021
Editada: Tariq Hammoudeh
el 1 de En. de 2022
I am building a game of battleship, and i have this function to create a figure for the boards.
now when ever i try to call it in a switch case using:
menu= menu(' play game',.....)
switch menu
case 1
setup
case 2
.
.
I keep get this error:
Error in Matlab>setup (line 93)
for ii = 1:(bs^2)
Error in Matlab (line 58)
setup
Can i please get help with how to fix it.
1 comentario
John D'Errico
el 30 de Dic. de 2021
Let me see if I understand. You are using the function named menu.
It returns a variable. You call that menu. Then you use menu in a switch case.
Should MATLAB know which version of menu should be used? The function? The variable? Even if you could make this work, do you understand how difficult your code will be to ever debug? An then, suppose you try to run this code twice in a row? MATLAB will now see a VARIABLE named menu. When you then try to use the FUNCTION named menu, MATLAB will get really confused, and throw an error.
What are the odds your code will run correctly? I certainly won't be taking any bets on the matter.
Respuesta aceptada
Voss
el 30 de Dic. de 2021
setup is a function that takes one input argument, bs, so when you call it you need to call it like:
setup(10); % to set up a board size of 10
or, equivalently:
my_board_size = 10;
setup(my_board_size);
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!