【发布时间】:2013-11-29 05:24:13
【问题描述】:
我有一个函数可以接收一个人的个性
function person = prompt_person ()
name = input ( ' Whats your name ? ' , 's' ) ;
day = input ( ' What day of the month were you born ? ') ;
month = input (' What month were you born ? ') ;
year = input ( ' What year were you born? ') ;
phone = input ( ' Whats your telephone number ? ') ;
date_of_birth = struct ('day', day, 'month', month, 'year', year) ;
person = struct ( 'name' , name, 'date_of_birth' , date_of_birth , 'phone' , phone ) ;
end
但我不断收到错误消息“Invalid field name "name"”、“prompt_person 中的错误消息(第 8 行)而且我不知道出了什么问题,因为我尝试创建一个更简单的小测试函数:
function [out] = tes( )
word=input('Insert word here ','s');
num=input('Insert number here ');
out= struct('Number1', word, 'Number2', num);
end
而且它工作得很好,尽管它似乎与在第一个函数中让我陷入 toruble 的代码完全相同。有什么想法吗?
【问题讨论】:
-
尝试使用
personName作为变量名。 -
无法在此处重现...您使用的是哪个 MATLAB 版本?
-
我正在使用 Matlab r2013a