how do i ask for several inputs.

for instance a diet diary with types of food and amounts.
here is the problem we were given.
Problem 2: The following table lists the protein, fat, carbohydrate, and energy content of a number of common foods. Write a MATLAB program that computes the total grams of protein, fat and carbohydrates consumed daily based on the amount of each food type consumed during the day. The program should query the user to input the number of food items eaten during the day, the specific foods that were eaten, and the amount of each specific food eaten. Based on this information, the program should perform the following tasks:
a. Compute the total solids and water intake for the day (assume that the solids content is 30% and the water content is 70%).
b. Compute the total grams of protein, fat, and carbohydrates derived from each food.
c. Compute the available energy from protein, fat and carbohydrates eaten during the day (assume the available energy in food is as follows: carbohydrates – 4 calories/gram, fat – 9 calories/gram, and protein – 4 calories/gram).
d. Compare the available energy from protein, fat and carbohydrates obtained in c above to the average for Americans of 15% from protein, 40% from fat, and 45% from carbohydrates.
The MATLAB program should output the following:
a. Total solids and water intake for the day.
b. A labeled table listing the total grams of protein, fat, and carbohydrates derived from each food and the total grams of protein, fat, and carbohydrates consumed for the day.
c. A pie graph comparing the percentage fat, protein and carbohydrates in the daily diet.
d. A bar graph comparing the energy derived from protein, fat, and carbohydrates for the day to that for the average American diet.
Protein, Fat, Carbohydrate, and Energy Content of Food
Food %Protein %Fat %Carbohydrate Fuel value/100 g (kcal)
Apples 0.3 0.4 14.9 64
Asparagus 2.2 0.2 3.9 26
Bacon, broiled 25.0 55.0 1.0 599
Bread, white 9.0 3.6 49.8 268
Cheese 23.9 32.3 1.7 393
Milk, whole 3.5 3.9 4.9 69
Oatmeal 14.2 7.4 68.2 396
Orange 0.9 0.2 11.2 50
Pork, ham 15.2 31.0 1.0 340
Potatoes 2.0 0.1 19.1 85
Provide a flow chart that describes the Program and output for the following test data:
Breakfast: 200 g Oatmeal, 75 g milk, 1 orange (225 g)
Lunch: 1 apple (100 g), 4 slices bread (100 g), 90 g bacon, 40 g cheese
Dinner: 350 g pork, 150 g asparagus, 150 g potatoes, 2 slices bread (50 g)

1 commentaire

Star Strider
Star Strider le 16 Fév 2016
Modifié(e) : Star Strider le 16 Fév 2016
So, you’re Ben Sturgeon’s classmate at Louisiana Tech?

Connectez-vous pour commenter.

Réponses (2)

Walter Roberson
Walter Roberson le 15 Fév 2016

0 votes

inputdlg() is one way. If your needs are more complicated than what can be handled with inputdlg() then you should probably write a GUI to accept the input.
inputdlg() is, by the way, a GUI itself; it does not do anything that you could not do yourself. But it is nice to have inputdlg() so that we do not need to recreate the functionality.

1 commentaire

Walter Roberson
Walter Roberson le 16 Fév 2016
See input() and pay attention to the 's' option.

Connectez-vous pour commenter.

Image Analyst
Image Analyst le 16 Fév 2016

0 votes

Here is the snippet I usually post. Feel free to adapt as needed (more inputs, different wording, etc.)
% Ask user for two floating point numbers.
defaultValue = {'45.67', '78.91'};
titleBar = 'Enter a value';
userPrompt = {'Enter floating point number 1 : ', 'Enter floating point number 2: '};
caUserInput = inputdlg(userPrompt, titleBar, 1, defaultValue);
if isempty(caUserInput),return,end; % Bail out if they clicked Cancel.
% Convert to floating point from string.
usersValue1 = str2double(caUserInput{1})
usersValue2 = str2double(caUserInput{2})
% Check for a valid number.
if isnan(usersValue1)
% They didn't enter a number.
% They clicked Cancel, or entered a character, symbols, or something else not allowed.
% Convert the default from a string and stick that into usersValue1.
usersValue1 = str2double(defaultValue{1});
message = sprintf('I said it had to be a number.\nI will use %.2f and continue.', usersValue1);
uiwait(warndlg(message));
end
% Do the same for usersValue2

Catégories

En savoir plus sur Food Sciences 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!

Translated by