Effacer les filtres
Effacer les filtres

how to store data at non zero place of matrix

1 vue (au cours des 30 derniers jours)
Nilesh Mate
Nilesh Mate le 1 Nov 2017
Commenté : Jan le 3 Nov 2017
I have following column vector A=[0;25;35;0;-65;0] Now at place of non zero coefficient of A, I have replace it with following column vector values. B=[48.23;-57.23;-100.29] So the final matrix will be A=[0;48.23;-57.23;0;-100.29;0]

Réponse acceptée

Birdman
Birdman le 1 Nov 2017
Modifié(e) : Birdman le 1 Nov 2017
ind=find(A~=0)
A(ind)=B
  1 commentaire
Jan
Jan le 3 Nov 2017
The editor should show a mark, that this code could be improved: Simply omit the find to apply a faster "logical indexing":
A(A ~= 0) = B

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by