How can i scan Column A in a matrix and if its true to have it average values in Column C
조회 수: 2 (최근 30일)
이전 댓글 표시
Basically i have a excel file full of information in 3 different columns which are about 5000 rows long and i need to know if there is a way to have matlab scan the first column until it finds what i have prompted the user to enter. Once it finds the first instance in column A to be true i need it to immediately go to column C and average the current value as well as the next 20 values starting with the first.
Basically i want to tell matlab to search column A for 'United States' if its true switch to column C and average the current value and the next 20 is this possible? If so how would i go about doing it. Thanks.
댓글 수: 0
채택된 답변
Simon
2013년 12월 11일
Hi!
So you already imported your data into matlab? What kind of matrix do you have? Is it a cell array with strings in the first column? What is in the third column?
If you have a cell array "C" with strings in the first column, you may find the user input "str" with
% logical vector of found strings
tf = strcmp(str, C(:, 1));
% do we have something?
if ~isempty(tf)
% positions (rows) in C
ind = find(tf);
% average for each found string
for n = 1:length(ind)
% this depends on the kind of matrix you have
mean([C{ind(n):ind(n)+20}])
end
end
댓글 수: 0
추가 답변 (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!