- 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?
11 views (last 30 days)
Show older comments
Hello,
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.
Thanks!
0 Comments
Answers (1)
Rajani Mishra
on 29 Jul 2020
The two steps asked are:
load patients
T = table(Age,Height,Weight,...
'RowNames',LastName);
% 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,:)
Second step:
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
0 Comments
See Also
Categories
Find more on Get Started with MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!