How to find values for corresponding start and end positons

조회 수: 18 (최근 30일)
Wind flower
Wind flower 2019년 6월 20일
편집: madhan ravi 2019년 6월 21일
My data is as follows stored in excel.
bit bit2
1 3
1 5
1 22
1 25
0 10
0 15
1 17
1 19
1 12
I had to find the position of first and last 1 bit of each set of 1 .. so i got answer lik this
start 1 7
end 4 9
Now i have to print or save (excel or word) bit2 values for corresponding start and end positons
  댓글 수: 2
Akshay Malav
Akshay Malav 2019년 6월 20일
Can you please elaborate your statement regarding finding position of first and last 1 bit and also the start and end mentioned by you
Wind flower
Wind flower 2019년 6월 21일
Capture.JPG
So i want the position of bit 1(colored) and its corresponding values of bit2 to be displayed

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

답변 (2개)

madhan ravi
madhan ravi 2019년 6월 21일
편집: madhan ravi 2019년 6월 21일
Getting the start and positions , i believe you know it from the previous question, so don‘t waste time using a loop.
bit1 =[...
1
1
1
1
0
0
1
1
1]
bit2 =[...
3
5
22
25
10
15
17
19
12];
Start = [1,7];
End = [4,9];
Positions = [Start;End].'; % first column represents start of each group and the second the end.
Sets = arrayfun(@(x,y)bit2(x:y),Positions(:,1),...
Positions(:,2),'un',0)

Akshay Malav
Akshay Malav 2019년 6월 21일
Here is the sample code
filename = 'mysheet.xlsx'; %read the excel filr
A = xlsread(filename); %store the content in A Matrix
[row col] = size(A); %find the size of the Matrix
array = []; %array which will have the bit2 value
i=1;
while i<=row %iterating through the bit 1 column
j=i;
if A(j,1)==1 % the starting point of the set of 1
array = [array A(j,2)]; % store the corresponding bit2 in array
while j<=row & A(j,1)==1 % loop till we find 0
j=j+1;
end
array = [array A(j-1,2)]; %store the final bit2 value
i=j;
else % update i
j=j+1;
i=j;
end
end

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by