Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

Insert 0s in a column matrix with an if function

2 visualizaciones (últimos 30 días)
Ricardo Higinio Picon Alvaro
Ricardo Higinio Picon Alvaro el 27 de Feb. de 2018
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
Hi, I want to insert 0s in a matrix where an entry is missing. For example: Say I've got matrices T1=[1;2;4;6;9;10] and B=[1;1;1;1;1;1] and another matrix T2=1:10. Values in B correspond to values in T1 so I want that every time that there is a missing value it inserts a zero. Finally B would be, B=[1;1;0;1;0;1;0;0;1;1] (zeroes where T1 was missing a value. Thank you

Respuestas (1)

Jos (10584)
Jos (10584) el 27 de Feb. de 2018
Something along these lines?
T1 = [1;2;4;6;9;10]
B = [1;1;1;1;1;1]
T2 = 1:10
A(T2) = 0
A(T1) = B
  2 comentarios
Ricardo Higinio Picon Alvaro
Ricardo Higinio Picon Alvaro el 27 de Feb. de 2018
Hi, sorry about the error T2 should be T2 = 1:10'. Basically T1 is matrix T2 but with missing values. The values of B correspond to the values in T1 (T1(k) corresponds to B(k)). So what I want it to replace the missing values of B with 0s having in mind the missing values of the other matrix T1. So if T1 is missing k=3,5,7,8 then values of B for k=3,5,7,8 should equal 0, shifting the other values to the other positions.
Jos (10584)
Jos (10584) el 27 de Feb. de 2018
That was already clear. If you want to have it into B, do:
B = A
et voila!

La pregunta está cerrada.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by