Error message when creating a structure
显示 更早的评论
I am not very good at this, and can't see what I am doing wrong.
I'm supposed to make a function that takes in a structure "date", and returns it like this : 20.05.1990. This is what I have:
date = struct('day',20,'month',05,'year',1990)
function print_date(date)
fprintf ('%i.%02.0f.%01.0f', date.day , date.month , date.year);
end
Now I am supposed to make a new structure where one of the fields calls this function:
person = struct('name','per', 'phone', 48151623, 'day_of_birth', print_date(date))
I then get the error message: too many output arguments. What am I doing wrong? I am not allowed to use built in functions.
回答(1 个)
Walter Roberson
2012-11-3
0 个投票
You have defined your function print_date to output a string to the command line window, and to return no values. However, you then use print_data(date) in a context that implies it is to return a value that will be inserted into the struct() you are creating.
Hint: sprintf()
类别
在 帮助中心 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!