How do I loop vector calculations and store them in another vector?
조회 수: 3 (최근 30일)
이전 댓글 표시
I have a list of two sets of vectors with names ranging x1 to x102 and y1 to y 102. I want to calculate the sum count from the y vector in the corresponding bins in the x vector over all 102 and store them in one vector with 102 bins.
How do I do this?
This is the code I wish to iterate over all 102 x'num' and y'num' vectors. Remember, x1 is a vector itself and the number stored in the ith bin in the z vector sums the y values in the corresponing bins in the x vector. I imagine looks like the following
iterate from i=1 to 102
z(i)= sum(yi(find(xi >= 1495 & xi <= 1505)))
end
댓글 수: 0
답변 (1개)
Adam
2014년 9월 5일
편집: Adam
2014년 9월 5일
Store your data in two 2d matrices x and y instead of 204 individually named variables, then it is just a simple indexing case. i.e. x is a (102 * n) matrix where n is whatever the length is of your x vectors. If each of your x vectors can be different length then it is probably simplest to use a cell array although a 2d matrix of a size large enough to hold the longest vector would also work.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!