Constructing matrix elements conditionally (and sequentially)
Ältere Kommentare anzeigen
Hi,
I have two matrices of differing lengths:
A = [1 1 0 1 0 0 1 0 1 0 1] B = [25.4 17.3 11.6 9.2 14.3 15.0]
I want to construct a matrix (C) that is the same length of A, but the 1 values are sequentially replaced by those in matrix B to yield:
C = [25.4 17.3 0 11.6 0 0 9.2 0 14.3 0 15.0]
Can anyone direct me to any relevant functions/methods that can do this?
As an aside, sum(A)==length(B) in all cases. However, sum(A) and length(B) will both vary with each iteration.
Thank you immensely.
Dave
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!