excel make rows equal

조회 수: 1 (최근 30일)
Abdul Asif
Abdul Asif 2020년 11월 18일
답변: Pratheek Punchathody 2020년 11월 23일
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
Pratheek Punchathody 2020년 11월 23일
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에서 Spreadsheets에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by