Error message when creating a structure
Afficher commentaires plus anciens
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.
Réponses (1)
Walter Roberson
le 3 Nov 2012
0 votes
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()
1 commentaire
Elisabeth
le 3 Nov 2012
Catégories
En savoir plus sur Structures dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!