I want to sort a data like this as given below

조회 수: 1 (최근 30일)
RAJAN PRASAD
RAJAN PRASAD 2016년 8월 5일
편집: Stephen23 2016년 8월 6일
0 0 3 4 5 0 0 0 0 10 11 12 13 14 15 0 0 0 0 20 21 22 0 0 0 is the data in which i have to subtract (5-3),(15-10),(22-20) can anybody tell me how to do it
  댓글 수: 2
Stephen23
Stephen23 2016년 8월 5일
@ RAJAN PRASAD: your question is not clear: do you want to sort the data (as your title states), or do you want to calculate differences between values (as your examples shows) ?
RAJAN PRASAD
RAJAN PRASAD 2016년 8월 6일
I wanted to subtract only it helped

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

채택된 답변

Stephen23
Stephen23 2016년 8월 5일
편집: Stephen23 2016년 8월 6일
This code locates the beginning and end values of any non-zero sequence, and calculates their differences:
>> X = [0,0,3,4,5,0,0,0,0,10,11,12,13,14,15,0,0,0,0,20,21,22,0,0,0];
>> Y = diff([0,X,0]>0);
>> X(Y(2:end)<0) - X(Y(1:end-1)>0)
ans =
2 5 2
Have a look at X(Y(2:end)<0) and X(Y(1:end-1)>0) if you want to know how this works.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by