Borrar filtros
Borrar filtros

Move all the values of matrix starting from particular row of matrix and replace by zeros

1 visualización (últimos 30 días)
Hello,
I have matrix A 343x9(attached with this thread). I want to check the condition A(k,4)==A(k+1,2). If true, leave it as it is. If false, move the matrix by one row starting from this row and substitute the values of the row by zeros. The challenge is that the matrix size is going to change.
The output is expected to be like:
20 303.679200000000 154.555100000000 303.794200000000 151.565800000000 0 0 2.99151123848801 70
21 303.794200000000 151.565800000000 305.288900000000 146.046900000000 0 0 5.71772553556046 70
22 305.288900000000 146.046900000000 306.553600000000 142.367700000000 0 0 3.89049851947021 70
23 306.553600000000 142.367700000000 301.609600000000 140.298100000000 0 0 5.35969963337501 70
24 301.609600000000 140.298100000000 299.080200000000 139.033300000000 0 0 2.82799989391797 70
25 299.080200000000 139.033300000000 297.010600000000 138.228500000000 0 0 2.22057361958570 70
0 0 0 0 0 0 0 0 0
26 518.224900000000 225.150500000000 507.187100000000 230.324500000000 0 0 12.1902955189774 70
27 507.187100000000 230.324500000000 505.002600000000 236.763100000000 0 0 6.79908892499577 70
28 505.002600000000 236.763100000000 503.507900000000 239.982500000000 0 0 3.54945974058021 70
29 503.507900000000 239.982500000000 501.898200000000 244.696500000000 0 0 4.98125788230243 70
30 501.898200000000 244.696500000000 499.483700000000 250.330300000000 0 0 6.12939741654920 70

Respuesta aceptada

Jan
Jan el 11 de Abr. de 2017
Editada: Jan el 11 de Abr. de 2017
Index = cumsum([1; 1 + (A(1:end-1, 4) ~= A(2:end, 2))]);
B(Index, :) = A;

Más respuestas (0)

Categorías

Más información sobre Data Type Identification en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by