Finding specific values in an array

37 ビュー (過去 30 日間)
Brady Wayne Robinson
Brady Wayne Robinson 2018 年 9 月 27 日
回答済み: Star Strider 2018 年 9 月 27 日
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.

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by