Matlab- summing of vectors in a matrix

In summary, to sum all the elements in a vector in Matlab, you can use the built-in sum() function. Additionally, you can sum specific rows or columns in a matrix by specifying the desired rows or columns as indices in the sum() function. To sum multiple vectors in a matrix, use the 'all' option. You can also skip certain values while summing vectors by using logical indexing. Lastly, the isequal() function can be used to check if the sum of a vector in a matrix is equal to a specified value.
  • #1
jaobyccdee
33
0
I have a 8000x600 Matrix called V. How can i add the colume 1,5,9,13,17... (all colume of (4*i+1) for i from 0 to 149) of the vector?
 
Physics news on Phys.org
  • #2
Say that the matrix is called V

Code:
i = [0:149]*4 +1;
sum(V(:,i)');
 

1. How do I sum all the elements in a vector in Matlab?

To sum all the elements in a vector in Matlab, you can use the built-in sum() function. Simply pass the vector as an argument to the function, and it will return the sum of all the elements.

2. Can I sum specific rows or columns in a matrix in Matlab?

Yes, you can sum specific rows or columns in a matrix in Matlab by specifying the desired rows or columns as indices in the sum() function. For example, to sum the first column of a matrix A, you can use sum(A(:,1)).

3. How do I sum multiple vectors in a matrix in Matlab?

You can sum multiple vectors in a matrix in Matlab by using the sum() function with the 'all' option. This will sum all the elements in the matrix, regardless of their dimensions.

4. Is it possible to sum vectors in a matrix while skipping certain values?

Yes, you can use logical indexing to skip certain values while summing vectors in a matrix in Matlab. You can create a logical array with the values you want to skip and use it as an index in the sum() function.

5. How can I check if the sum of a vector in a matrix is equal to a certain value in Matlab?

You can use the isequal() function in Matlab to check if the sum of a vector in a matrix is equal to a certain value. This function will return a logical value of true if the sum is equal to the specified value, and false otherwise.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
819
  • MATLAB, Maple, Mathematica, LaTeX
Replies
32
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
563
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
858
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
Back
Top