Array Indexing, Array within an Array

4 visualizzazioni (ultimi 30 giorni)
Christopher Wible
Christopher Wible il 19 Giu 2019
Risposto: Matt J il 19 Giu 2019
I need help understanding how this code works.
Consider the variables B = [1 5 8] and D = [1; 1; 1]. When I write the code B(D,:) I am getting the output of [1 5 8; 1 5 8; 1 5 8] and I am not sure why.
Please be thorough in your explination.
Thanks for the help.

Risposta accettata

Matt J
Matt J il 19 Giu 2019
Because, by definition,
B(D,:) = [ B(D(1),:) ; B(D(2),:) ; B(D(3),:) ]
= [ B(1,:) ; B(1,:) ; B(1,:) ]
= [1 5 8; 1 5 8; 1 5 8]

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by