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
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에 대해 자세히 알아보기

태그

질문:

2012년 11월 3일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by