How to get data by using index numbers and store in new array?

조회 수: 3 (최근 30일)
Shahab Khan
Shahab Khan 2018년 12월 4일
답변: Shahab Khan 2018년 12월 4일
I have an array with some zeros and some positive numbers.
I already have a code which provide me index numbers of positive data location.
idx =
141 212
370 426
608 642
843 912
1154 1177
1481 1496
1732 1779
2128 2161
2343 2377
2578 2649
2838 2908
Index number
141 to 212
has some positive valued which sum is equal to 50.
What I want to do is to sum up data between each index number calculated early and store it in a new array.
Expected result should be like
Result =
50
90
1000
600
45
658
55
821
22
444
845

채택된 답변

Shahab Khan
Shahab Khan 2018년 12월 4일
Actually I manage to figure it out.
Here is solution, thought may be helpful for some others.
% idx is an array having index numbers
Result = zeros(length(idx),1); % define size of result
for i= 1:length(idx)
data = EnergyB((idx(i,1)):idx(i,2));
Result(k) = sum(data/3.6/1000000) % use 3.6/1000000 for converting joules to kWh

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by