Finding specific values in an array
조회 수: 77 (최근 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!
댓글 수: 0
답변 (3개)
Adam Danz
2018년 9월 27일
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
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).
댓글 수: 0
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!