Filter löschen
Filter löschen

Reduce dimension of a vector

1 Ansicht (letzte 30 Tage)
Salvatore Turino
Salvatore Turino am 23 Jan. 2012
Hello at the beginning of my code i declare a vector
riga_save=save_rig;
where save_rig is 1x14. after some works on the indices at the end of my code i find this:
riga_save =
2 3 9 10 11 15 0 0 0 0 0 0 0 0
in my code i go to put all zeros in riga_save at the beginning and then i go to replace these zeros with some indices of save_rig...so at the end i find all these 000 given by the oversized, since the vector save_rig is bigger then riga_save. how can i remove the 0 0 0 given by the oversized?
thank you

Akzeptierte Antwort

Salvatore Turino
Salvatore Turino am 23 Jan. 2012
i've done this:
app_save=riga_save;
clear riga_save
for i=1:length(colonna_save)
riga_save(i)=app_save(i);
end
i want to know if there is something with more efficiency.

Weitere Antworten (1)

Andrew Newell
Andrew Newell am 23 Jan. 2012
I would use find inside riga_save to extract the nonzero indices.
It may be more efficient, though, to have save_rig return logical indices (see Logical indexing).
However, to answer the question you actually asked, you can do this:
riga_save = riga_save(riga_save>0);
This is also an example of logical indexing!
(EDITED to correct answer)
  1 Kommentar
Salvatore Turino
Salvatore Turino am 23 Jan. 2012
it doesn't work. i need to remove the 0.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by