sum of range of matrix elements from starting and end point
19 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Abhijit Sardar
am 1 Jan. 2021
Kommentiert: KALYAN ACHARJYA
am 3 Jan. 2021
I have 90000*20 matrix i want to add 50 elements of 18th column successively. how can i do so please help.also could you please tell how to do sum of elements in the vector if the starting and end point is known.
0 Kommentare
Akzeptierte Antwort
KALYAN ACHARJYA
am 1 Jan. 2021
Bearbeitet: KALYAN ACHARJYA
am 1 Jan. 2021
Lets say the matrix data is variable name as "mat"
result=sum(mat(1:50,18))
"could you please tell how to do sum of elements in the vector if the starting and end point is known".
If 1-D vector, you can use sum directly
result=sum(mat(Start_index:End_index))
For 2 D case
data=mat(From rows:Till Rows number,From columns:Till Columns number)
result=sum(data(:))
4 Kommentare
KALYAN ACHARJYA
am 3 Jan. 2021
In that case you have to use array indexing
l=1;
res=zeros(1,,,,expected_num_of interation); % Must do
for i = 1:p-50
res(l)= sum(m(i:i+50,18))
end
In this case you can avoid loop, please use movsum, as follows (Recommended)
data=m(:,18);
sum_result=movsum(data,50)
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!