excel make rows equal

1 次查看(过去 30 天)
Abdul Asif
Abdul Asif 2020-11-18
above there is a file called kilos.xls
in matlab I want to use readtable to load in the data then I want the user to use a menu to select a state then I want to print the number of fans and the percentage of people who lose interest into the command window for example if in the menu I choose texas I want to output in the state texas there are 400 fans and 45% of peope lose interest in the command window
I know how to use the readtable and menu function but what I need help with is when I select an option from state how do I print the other numbers in the command window

回答(1 个)

Pratheek Punchathody
Hi Abdul
I have imported the data from the file kilos.xlsx. Using the "readtable()" the data is imported into the workspace. With the "height()" function the total number of rows is calculated.
Please use the following code to get the name of the state as an input from the user and display the totalNumberOfFans and peopleWhoLoseInterestInTheSport with respect to the entered state by the user.
x = readtable(' kilos.xlsx'); %import the table to the workspace
h = height(x); %calculate the number of rows in the table
prompt = "Enter the state"; %Prompt message in the workspace
str = input(prompt,'s'); %Request user input
for i=1:h %logic to iterate through the rows of the table
t = strcmp(str,x.state(i)); %compare strings and get logical output
if(t==1)
disp(x(i,:)); %Display the respective row as an output
break;
end
end
Refer to the documentation of Request user input for further information. Also refer to strcmp() if you need more information on comparing strings.
Hope this helps.

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by