You can use the input
function to ask the user which operation they want to perform. Here is a sample code to achieve the required functionality:
main.m491 chars20 lines
In this code, we first define a sample data array. We then use the input
function to ask the user which operation they want to perform. We store the user input in the variable op
.
We then use a switch
statement to perform the selected operation. If the user selects option 1, we delete zeros from the data using logical indexing. If the user selects option 2, we replace zeros with the mean of data using logical indexing and then assign the mean to the zeros.
If the user inputs an invalid option, we display a message saying "Invalid input".
gistlibby LogSnag