How do I loop vector calculations and store them in another vector?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Adam
el 5 de Sept. de 2014
Editada: Adam
el 5 de Sept. de 2014
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 comentarios
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!