Finding specific values in an array

57 views (last 30 days)
Brady Wayne Robinson
Brady Wayne Robinson on 27 Sep 2018
Answered: Star Strider on 27 Sep 2018
I have data in excel that is 17 columns by 4800 rows. The 17 columns represent different muscles, and the rows represent times they are "activated." For each column I need to know which numbers in that column are greater then 10 and what that number is. Once I find all those different numbers I need to sum them up. Just uncertain how to do this. Thank You!

Answers (3)

Adam Danz
Adam Danz on 27 Sep 2018
First read data in from excel and store in a matrix; see xlsread() .
Let's say your matrix is named 'm'. First I create a logical matrix identifying where numbers meet threshold. Then I replace all other numbers with NaNs. Finally, I add up each column.
meetsThreshold = m > 10;
m(~meetsThreshold) = NaN;
mSum = nansum(m,1);

Bish Erbas
Bish Erbas on 27 Sep 2018
Use xlsread to import Excel data into a numeric data in a matrix. Once your data is available in MATLAB Workspace, you can then perform any operations you desire including finding values and their indices which are greater than 10. You can either use the find function or use the comparison operator as an index like A(A>10).

Star Strider
Star Strider on 27 Sep 2018
One approach:
data = randi(20, 4800, 17); % Create Data
[r,c,v] = find(data > 10); % Rows, Columns, Values
colG = findgroups(c); % Define ‘Groups’ By Column
rowsvals = splitapply(@(x){x}, [r,v], colG); % Corresponding Rows & Values
query = [rowsvals{1}(1:5,:) rowsvals{17}(1:5,:)] % Sample Resulting Output (Delete)
Note that ‘data’ will be the double-precision matrix from your spreadsheet.

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!