我試圖創建一個結構數組並提示用戶分別填充其字段。結構失敗的Matlab數組
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','')
但我不斷收到同樣的錯誤一段原因。
任何想法我做錯了,將不勝感激。謝謝。
沒有。我的文件現在保存爲「書籍」。它不斷拋出該錯誤。 – iksimen
是你的代碼'函數struct'的第一行,還是這種性質的東西?那個錯誤還是很清楚的。 MATLAB **認爲**你的文件叫做'struct'。嘗試**清除所有變量**並再次運行您的代碼。清除一切;'。 – rayryeng
@iksimen - 我只是在我的終端上運行了這段代碼,它工作正常。有些東西在創建該文件時沒有告訴我們。你要麼放一個不好的函數聲明,要麼你的工作空間有一個名爲'struct'的變量,或者你的工作目錄或當前的MATLAB路徑中有一個名爲'struct'的文件。無論哪種方式,我沒有什麼可以複製的,因爲你沒有給我所有的東西。 – rayryeng