Creating if, else statement for Excel columns

조회 수: 1 (최근 30일)
Ashley VanSumeren
Ashley VanSumeren 2019년 1월 13일
답변: Siddharth Bhutiya 2019년 1월 17일
I am trying to interpret force data from an Excel file and trying to use an if else statement for which columns to use, then finding the max force of each column being used. There's 20 columns that I'm looking at and I need data from only 5 of them. A column will be used if the minimum is 500 N or greater. I cannot use use a column if it doesn't meet that minimum requirement.
Currently I have this, but am not sure how to finish executing it:
FP1 = xlsread('P19_SHOES.xlsx','B5:K105');
if min(FP1,[],1)>=500
FP1_Max = max(FP1,[],1)
else
FP1_Max = 0
end
Currently when I run the code, I'm getting FP1_Max = 0 as the output.

답변 (1개)

Siddharth Bhutiya
Siddharth Bhutiya 2019년 1월 17일
min(FP1,[],1)>=500
In your code snippet the above line would give you a logical array indicating if a column meets your requirement of having a minimum value of 500. Once you have this you can index into the original matrix to obtain a new matrix that contains only those rows as follows
desrired_columns = min(FP1,[],1)>=500;
FP1_new = FP1(:, desired_columns);
The new matrix with the desired columns can be used for further analysis. For example, to get the max values you can do something like this
FP1_max = max(FP1_new,[],1);

카테고리

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