简体   繁体   中英

How to search a cell array in MATLAB?

My program asking the user to rent and return movies. I have a list of movies made in excel and have the program load and read them. The user has a choice of 'rent' or 'return'. If they are renting the program randomly picks a movie that is stored in the excel. From here i want to change the available from yes to no if they chose to rent that one. How can i do that?

If the user chooses return i ask to enter the movie name. How can i search the excel to find the column the movie is in to change the available from no to yes? Also i want the user to be able to rent the movie watched. This is all i have for that section:

 [num text raw] = xlsread('all_movies.xlsx');
 prompts = {'What movie are you retunring?'};
 returning = inputdlg(prompts);
 strcell = (text);
 strfind(strcell)

Have you considered storing the movies as a struct ? each movie is a fieldname in the struct and the values for each field would be whether it is rented or not, etc.

See here how to use string variables to access fields of structs.

add a column to your excel file indication availability status (eg 0 is available, 1 is rented). that should help with the first step.

second step: when you search for the movie, use strcmpi , which will give you a logical vector with 1 indicating the array location, thus which row in your Excel file that has that movie title

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM