MATLAB: Indexing in a cell array and deleting it.

structures

Hello. I am currently creating a library in Matlab and I'm using a structural array. For my library, I am trying to find a book by title and then display the book with title, author and number of pages. However currently it doesn't display the book, when i do it. The program adds a book to the library and then I can find that same book and display it with the title, author and page. However the current format I have does not display the book. Is it possible to isolate the book when its prompt and display it and/or delete it? Thanks for anyone who answers.
function library20
k = 0;
S = struct(); % creates a structural array
str = 'X';
while ~isempty(str)
str = input('What would you like to do: ', 's'); % asks user for a prompt
switch lower(str)
case 'add books'
k = k+1;
S(k).Title = input('Title: ', 's');
S(k).Author = input('Author: ', 's');
S(k).Pages = input('Number of Pages: ', 's');
fprintf('%s, %s, %s has ben added to the library\n', S(k).Title, S(k).Author, S(k).Pages)
case 'find book by title'
prompt=input('Please enter title of the book: ', 's');
if any(strcmp(S, 'prompt'))
disp(S)
end
end
end

Best Answer

prompt=input('Please enter title of the book: ', 's');
idx = find(strcmp({S.Title}, prompt)==1) ;
disp(S(idx))
Related Question