How to get menu to call code sections
14 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Aleksander Vae Haaland
el 19 de Sept. de 2019
Respondida: Aleksander Vae Haaland
el 19 de Sept. de 2019
I am working on a assignment where I am manipulation an image. All the code is written in code sections corresponding to the task number.
The last task on the assignment is to add a menu which runs the code for the different task.
For example: Task 2: Show image. Code: imshow(A).
Is there a way I can call the different code sections with my menu, can I create functions and call them, or do I need to copy all my code into the switch case section of my menu? The menu is the last task, therefore it is currently on the bottom of my code.
%% Task 1: Load the image data
A = imread('butterfly.jpg');
%% Task 2: Show image
function taskTwo
imshow(A);
end
%% Task 10: Menu
choice = 1;
while choice ~= 7
choice = menu('Toolbar', 'Task 2', 'Task 5', 'Task 6', 'Task 7', 'Task 8', 'Task 9', 'Exit');
switch choice
case 1
taskTwo
case 7
close all
end
end
1 comentario
Adam
el 19 de Sept. de 2019
Editada: Adam
el 19 de Sept. de 2019
Creating functions is the way to go definitely, as you appear to have already done in one case of the pasted code, although whether you can define a function in the middle of a script or not I'm not entirely sure, I've never tried. You can define them all at the end certainly, or in their own file.
You also need to take care of input arguments though unless you use nested functions, which I'm fairly sure you can only do if the top level if is a function, not a script. Otherwise you'd need to pass the arguments in to each function.
Respuesta aceptada
Más respuestas (0)
Ver también
Categorías
Más información sobre Startup and Shutdown en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!