I have a matrix that i import from xlxs file using the code
function[output] = second() [raw] = xlsread('errors168h.xlsx'); disp(raw) A = raw(:,1); B = raw(:,2); output=[A,B]; end
and the matrix i got is
A B1 12 13 14 25 26 27 18 19 210 211 2
How can i copy matrix from second column but only certain number? the other number will be random either 1 or 2. Example
A B | | A B1 1 1 | | 1 1 12 1 1 | | 2 1 13 1 1 | | 3 1 14 2 2 | | 4 2 25 2 1 | OR | 5 2 26 2 1 | | 6 2 1 7 1 1 | | 7 1 18 1 1 | | 8 1 19 2 2 | | 9 2 210 2 2 | |10 2 111 2 1 | |11 2 1
If the third row of 2 become 1, the rest of the column will become 1. process repeat until it reach another set of 2. Whenever it read number 1 on column B, it will stop processing and when it will start changing number again when it read 2 on column B. In short, it do like this
A B A B C------ ----------- 1 1 1 1 1 %copy normally to C
2 1 2 1 1 3 1 3 1 1 4 2 4 2 2 %read 2 at B. random 1 or 2. get 2
5 2 5 2 1 %read 2 at B. random 1 or 2. get 1
6 2 6 2 1 %read 2 at B. Follow previous value and set 1
7 1 7 1 1 %read 1. copy normally value to C
8 1 8 1 1 9 2 9 2 1 %read 2 at B. random 1 or 2. get 1 (start process like previous)
10 2 10 2 1 %read 2 at B. Follow previous value and set 111 2 11 2 1 %read 2 at B. Follow previous value and set 1
Best Answer