# Creating if, else statement for Excel columns

3 views (last 30 days)
Ashley VanSumeren on 13 Jan 2019
Answered: Siddharth Bhutiya on 17 Jan 2019
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:
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.

Siddharth Bhutiya on 17 Jan 2019
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);