# How to find out point of change of sequence of ones and zeros?

1 visualizzazione (ultimi 30 giorni)
Lukas Poviser il 27 Lug 2021
Commentato: Lukas Poviser il 28 Lug 2021
Hello,
I have this matrice:
1 NaN 3.28000000000000
1 NaN 3.32000000000000
1 NaN 3.36000000000000
1 NaN 3.40000000000000
0 0.0320040000000000 3.44000000000000
0 0.0697230000000000 3.48000000000000
0 0.124815600000000 3.52000000000000
0 0.158877000000000 3.56000000000000
and I would like to have another column where would be just the number where the first column changes from 1 to 0.
Result should be like this:
1 NaN 3.28000000000000
1 NaN 3.32000000000000
1 NaN 3.36000000000000
1 NaN 3.40000000000000 3.40000000000000
0 0.0320040000000000 3.44000000000000
0 0.0697230000000000 3.48000000000000
0 0.124815600000000 3.52000000000000
0 0.158877000000000 3.56000000000000
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

Jan il 27 Lug 2021
Modificato: Jan il 28 Lug 2021
What do you expect in the other rows of the 4th column? All rows must have the same number of columns, according to the definition of a matrix. If zeros are fine:
index = find(A(:, 1) == 0, 1) - 1; % [EDITED, -1 appended]
if any(index)
A(index, 4) = A(index, 3);
end
##### 5 CommentiMostra 3 commenti meno recentiNascondi 3 commenti meno recenti
Jan il 28 Lug 2021
Now you post another input, but do not mention, what you expect as output.
• If you still want to use the first change from 1 to 0, use the code of my answer.
• If you want to find all changes from 1 to 0:
index = strfind(A(:, 1).', [1, 0]);
B = A(index, 3);
% Alternative:
index = diff(A(:,1)) < 0;
Lukas Poviser il 28 Lug 2021
It works perfectly! Thanks!

Accedi per commentare.

### Categorie

Scopri di più su Operators and Elementary Operations in Help Center e File Exchange

R2020b

### Community Treasure Hunt

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

Start Hunting!

Translated by