Assigning value to an element in vector
Mostra commenti meno recenti
The problem is trivial but the code does not work. I wanted to replace 1 by -1 in a matrix
ip = [0 1 1 0;0 0 0 1]
X=find(ip == 1)
for i=1:length(X)
ip(X(i))=-1
end
But this does not work and is beyond my understanding. Is there any logical error here?
1 Commento
Azzi Abdelmalek
il 4 Set 2013
Modificato: Azzi Abdelmalek
il 4 Set 2013
Your code is correct
Is there any error message? If not what is the result?
Risposte (1)
Walter Roberson
il 4 Set 2013
0 voti
Runs correctly for me.
In your actual code, is it possible that what you really have for "1" is not an integer? For example if you were searching for 1.3 ? If so then
2 Commenti
xplore29
il 4 Set 2013
James Tursa
il 4 Set 2013
What do you get for this:
isequal(fix(ip),ip)
Categorie
Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!