필터 지우기
필터 지우기

How can I set a matrix value to equal a non-numeric coordinate?

조회 수: 1 (최근 30일)
Liam Vella
Liam Vella 2019년 5월 17일
편집: madhan ravi 2019년 5월 17일
For example, if part of a matrix equals 3, I want that coordinate to be (a,b). Then I want to be able to use that coordinate to change other values, such as writing (a,b+1)=4, to change the value in the next column to 4, or (a-1,b)=7 to change the value in the row above to 7.
Thanks.
This is what I've attempted and doesn't work:
clear, clc
x = randi(10,10);
x(x==3) = x(a,b);
Undefined function or variable 'a'.
Error in Lab4 (line 4)
x(x==3)=x(a,b);

답변 (1개)

madhan ravi
madhan ravi 2019년 5월 17일
편집: madhan ravi 2019년 5월 17일
[a,b]=find(x==3)% I don't see the point of this if your assigning the same value
x==3 % is already sufficient and efficient for indexing
  댓글 수: 2
Liam Vella
Liam Vella 2019년 5월 17일
When I write
clear, clc
x = randi(10,10);
[a,b] = find(x==3)
[a-1,b] = 7;
It doesn't work and the coordinate is not set to equal 7,
Why?
madhan ravi
madhan ravi 2019년 5월 17일
편집: madhan ravi 2019년 5월 17일
What is that your trying to do ? Write your expected result explicitly with a 3 by 3 matrix. the expression a-1 will error out if a is one.

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

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by