- Find a row from a table using the first input
- Multiply the row received after first operation according to the second input.
How do I use inputs to find and manipulate data in a table?
9 views (last 30 days)
I am working on a project where I have a table that shows data for different soups. In the table I have columns for the name, calories, cups, protein, carbs, etc.. and the rows are the different soups (i.e. tomato, chicken noodle, etc..). What I want to do is use two input functions to give an array of values for a specific row and the various columns. The first input would prompt the user to give the name of the soup. The second input would prompt the user to tell how many cups of the soup. What I'm trying to figure out is how to use both inputs together in a way where the first input would find the specific row (by searching the name), and the second input would take the values from that row and multiply them by the difference in number of cups. So that the final output would give data for that soup at a certain amount of cups. Any examples of code would be greatly appreciated!
Here's two images that better illustrate my question by using the same concept but with cereal instead of soup.
Rajani Mishra on 29 Jul 2020
The two steps asked are:
I have created a table for above operations, example table is taken from this link.
T = table(Age,Height,Weight,...
% Table created
For first step:
name = 'Williams' %Here I have stored row name dirctly in a variable,
% you can use the variable containing user input
T2 = T(name,:)
result = table2array(T2); % I have transformed the row received to a vector for
% multiplying it by a specific number
result = result * factor
%factor is multiplication variable calculated according to the second input