Indexing in a cell array and deleting it.
Mostra commenti meno recenti
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
1 Commento
KSSV
il 26 Apr 2017
Accept the answers for your questions and then ask the other questions. On the same code you have asked three questions and you have not accepted any answer, though you have used the code which users have given.
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Cell Arrays in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!