I have same values for all the 3 matrices
조회 수: 1 (최근 30일)
이전 댓글 표시
All the 3 matrices should show a diffent values but i get to see all are the same with a warning stating " The variable XXXX appeaqrs to change the sign on every loop iteration"
Here is the code:
for m=1:length(y)
for n=1:length(x)
r1source(m,n)=sqrt((x(n)-x1)^2+(y(m)-y1)^2);
r2source(m,n)=sqrt((x(n)-x2)^2+(y(m)-y2)^2);
r3source(m,n)=sqrt((x(n)-x3)^2+(y(m)-y3)^2);
end
end
댓글 수: 1
Rik
2021년 11월 3일
Without input data I don't see why the resulting matrices would be te same, nor where the warning would be coming from.
This can probably be done without a loop anyway, and if is can't you should replace length with numel, since that is probably what you mean.
답변 (1개)
KSSV
2021년 11월 3일
You need to initialize the variables which store data inside the for loop.
% Initilization
r1source = zeros(length(y),length(x)) ;
r2source = zeros(length(y),length(x)) ;
r3source = zeros(length(y),length(x)) ;
% loop
for m=1:length(y)
for n=1:length(x)
r1source(m,n)=sqrt((x(n)-x1)^2+(y(m)-y1)^2);
r2source(m,n)=sqrt((x(n)-x2)^2+(y(m)-y2)^2);
r3source(m,n)=sqrt((x(n)-x3)^2+(y(m)-y3)^2);
end
end
댓글 수: 13
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!