【发布时间】:2015-04-17 18:26:22
【问题描述】:
我正在尝试创建一个结构数组并提示用户单独填写其字段。
book =struct('name',{''}, 'author',{''}, 'pubdate',{''}, 'price',{})
nmbr=input('enter number of books');
books = repmat(book, nmbr, 1);
for i=1:nmbr
books(i).name = input(sprintf('enter name of book #(%d)',i), 's')
books(i).author = input(sprintf('entre author of book #(%d)',i), 's')
books(i).pubdate = input(sprintf('enter publication date of book #(%d)',i), 's')
books(i).price = input(sprintf('enter price of book #(%d)',i))
end
但是,当我不断收到此错误时,我遗漏了一些东西:
??? Attempt to call constructor struct with incorrect letter case.
Error in ==> struct at 1
book =struct('name',{''}, 'author',{''}, 'pubdate',{''}, 'price',{})
我尝试以不同的方式对结构进行 declrng
book =struct('name','', 'author','', 'pubdate','', 'price','')
但由于某种原因,我不断收到同样的错误。
任何关于我做错了什么的想法将不胜感激。谢谢。
【问题讨论】: