Finding specific values in an array

82 次查看(过去 30 天)
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!

回答(3 个)

Adam Danz
Adam Danz 2018-9-27
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 2018-9-27
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 2018-9-27
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.

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by