Finding specific values in an array
78 views (last 30 days)
Show older comments
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!
0 Comments
Answers (3)
Adam Danz
on 27 Sep 2018
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);
0 Comments
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).
0 Comments
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.
0 Comments
See Also
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!