error in replacing values

조회 수: 1 (최근 30일)
kash
kash 2012년 2월 21일
I have a matrix
39 77516 13 2174 0 40
50 83311 13 0 0 13
38 215646 9 0 0 40
53 234721 7 0 0 40
28 338409 13 0 0 40
i replace some values using
for i=1:5
for j=1:6
if (A(i,j)>17&&A(i,j)<=18.5)
A(i,j)=0.111;
end
if (A(i,j)>18.5&&A(i,j)<=20.5)
A(i,j)=0.112;
end
if (A(i,j)>20.5&&A(i,j)<=30)
A(i,j)=0.113;
end
if (A(i,j)>30&&A(i,j)<=40.5)
A(i,j)=0.114;
end
if (A(i,j)>40.5&&A(i,j)<=48)
A(i,j)=0.115;
end
if (A(i,j)>48&&A(i,j)<=54.5)
A(i,j)=0.116;
end
end
end
I get output as
1.0e+005 *
0.0000 0.7752 0.0001 0.0217 0 0.0000
0.0000 0.8331 0.0001 0 0 0.0001
0.0000 2.1565 0.0001 0 0 0.0000
0.0000 2.3472 0.0001 0 0 0.0000
0.0000 3.3841 0.0001 0 0 0.0000
I am not getting exact values which i want to replace ,please help
if i want to replace 0.111,0.112,i end uo getting only
1.0e+005 *0.0001 for all values,pleasehelp

채택된 답변

G A
G A 2012년 2월 21일
use format('long') before output and you will see that everything is OK
  댓글 수: 1
G A
G A 2012년 2월 21일
and, instead of for-loop you can use:
A(A>17&A<=18.5)=0.111;
A(A>18&A<=20.5)=0.112;
A(A>20&A<=30)=0.113;
A(A>30&A<=40.5)=0.114;
A(A>40&A<=48)=0.115;
A(A>48&A<=54.5)=0.116;

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Scope Variables and Generate Names에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by