필터 지우기
필터 지우기

Assigning value to an element in vector

조회 수: 1 (최근 30일)
xplore29
xplore29 2013년 9월 4일
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
Azzi Abdelmalek
Azzi Abdelmalek 2013년 9월 4일
편집: Azzi Abdelmalek 2013년 9월 4일
Your code is correct
Is there any error message? If not what is the result?

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2013년 9월 4일
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
xplore29
xplore29 2013년 9월 4일
this small script runs independently...thats true for mr as well. But in my big code this fails. And i am only dealing with integers and therefore getting into decimals is out of scope here.
i also tried
ip(ip==1)=-1
but this also fails in my main code.
James Tursa
James Tursa 2013년 9월 4일
What do you get for this:
isequal(fix(ip),ip)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by