在代码中,“createbook”和“displaybook”是我创建的函数,我知道这些工作并不是问题。如果有人可以帮助我,我会非常感激。如果您需要更多信息,请发表评论然后回复您
Books = [];
Choice = input('What would you like to do: ','s');
while (Choice)
if Choice == 'add book'
Title = input('Enter the title: ','s');
Author = input('Enter the author: ','s');
Pages = input('Enter the number of pages: ');
New = createbook(Title, Author, Pages);
displaybook(New);
fprintf('%s has been added to the library\n',New)
Books = [Books New];
elseif Choice == 'quit'
disp('PROGRAM END')
return;
end
Choice = input('What would you like to do: ','s');
end
答案 0 :(得分:0)
使用strcmp代替(==)。原因是当您在Matlab中写入if(' string1' ==' string2')时,它返回一个布尔向量,它检查每个索引i是否为(str1 [i] ] == str2 [i])。如果两个字符串具有不同的长度,则会抛出异常