필터 지우기
필터 지우기

summation of diffrent lengths in vector

조회 수: 2 (최근 30일)
Sakhr
Sakhr 2011년 10월 12일
I would like to sum some lengths in vector. For example I have a=[0.0 0.0 0.3 0.4 0.5 0.0 0.0 0.0 0.0 1.0 1.1]. I need b=((0.5-0.3)+(1.1-1.0))=0.3. The time step is constant=0.1 and this order of elements can be change in new run of the program.Thanks alot.
  댓글 수: 1
Grzegorz Knor
Grzegorz Knor 2011년 10월 12일
According to what rules you want to sum up? Could you explain?

댓글을 달려면 로그인하십시오.

채택된 답변

Clemens
Clemens 2011년 10월 12일
I would do this with some logical indexing magic.
a=[0.0 0.0 0.3 0.4 0.5 0.0 0.0 0.0 0.0 1.0 1.1];
step = 0.1;
tmp = a>0; % rule what elements to take
i_sum = tmp(1:end-1) & tmp(2:end)>0; % magic removes 1 element from each group
distances = sum((i_sum))* step % = 0.3
  댓글 수: 1
Sakhr
Sakhr 2011년 10월 12일
It works fine,really magic, thanks for help

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Sensors and Transducers에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by