Filter löschen
Filter löschen

Marking indexes

1 Ansicht (letzte 30 Tage)
Raviteja
Raviteja am 19 Apr. 2011
x=[1 7 12 16];
y=zeros(1,20);
I want to show 1 in y at x valued indices.. i.e,
y(1)=1
y(7)=1
y(12)=1
y(16)=1
y(for all)=0
how I can stem it automatically without manually zero padding ?

Akzeptierte Antwort

Laura Proctor
Laura Proctor am 19 Apr. 2011
I think that all you want to do is this:
x = [ 1 7 12 16 ];
y = zeros(1,20);
y(x) = 1
If y is rather large, you can create a SPARSE matrix:
y = sparse(1,20);
y(x) = 1

Weitere Antworten (0)

Kategorien

Mehr zu Sparse Matrices finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by