Azzera filtri
Azzera filtri

If I have a list of numbers how can I enter a 1 in a matrix position with the list of numbers

1 visualizzazione (ultimi 30 giorni)
My list of numbers is 1690 numbers long with random numbers
list = [ 1, 2, 3, 4, 6, 7, 9...]
My initial matrix is zeros
initmat = zeros(2387,1);
My goal is to get the number 1 into the correct position in the initial matrix from the list (for instance a 1 in the first, second, fourth, sixth, ninth position etc).
I want my final matrix to look like finalmat, but I the list is too long to do by hand
finalmat = [1, 1, 1, 1, 0, 1, 1, 0, 1...]

Risposta accettata

Walter Roberson
Walter Roberson il 15 Giu 2018
initmat(list) = 1;
Another way of handling this as a single step is
finalmat = accumarray(list(:), 1);
or
finalmat = full( sparse(list, 1, 1) );

Più risposte (0)

Prodotti


Release

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by