answer=inputdlg({'nodes'});
nodes=str2double(answer(1,1));
nodematrix=Inf(nodes);
A=1;
B=0;
answer=[];
while A < nodes
B = B+1;
while B < nodes
B = B+1;
answer = str2double(inputdlg(['Enter resistance between ',num2str(A),' and ',num2str(B)]));
nodematrix(A,B) = str2double(answer)
nodematrix(B,A) = str2double(answer)
end
A = A+1;
B = 1;
end
disp(nodematrix)
OUTPUT:
Inf NaN NaN NaN NaN
NaN Inf NaN NaN NaN
NaN NaN NaN NaN NaN
NaN NaN NaN NaN NaN
NaN NaN NaN NaN Inf
I was wondering why these are showing up as NaN?? And I also am trying to fill this where it does not ask to fill the diagonal.. The diagonal should always be zero. I don't know why its asking for those values..

 채택된 답변

KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 11월 5일
편집: KALYAN ACHARJYA 2019년 11월 5일

1 개 추천

See the example:
Get the data from inputdlg;
Say any number 3, 4,5,6 ........
Then
>> str2double(4)
ans =
NaN
>> str2double(7)
ans =
NaN
I have removed the str2double in answer statement, str2double convert strings to double precision values, not numeric data
answer=inputdlg({'nodes'});
nodes=str2double(answer(1,1));
nodematrix=nodes6;
A=1;
B=0;
answer=[];
while A < nodes
B = B+1;
while B < nodes
B = B+1;
answer =inputdlg(['Enter resistance between ',num2str(A),' and ',num2str(B)]);
nodematrix(A,B) = str2double(answer)
nodematrix(B,A) = str2double(answer)
end
A = A+1;
B = 1;
end
##
nodematrix =
6 5 6 7 8 3
5 0 6 7 8 2
6 6 4 7 3 6
7 7 7 8 5 0
8 8 3 5 5 6
3 2 6 0 6 0

댓글 수: 3

I'd call str2double once to create a double variable answer then simply assign that answer into the elements of nodematrix.
answer = str2double(inputdlg(...));
nodematrix(A,B) = answer;
nodematrix(B,A) = answer;
Actually, I'd probably just fill in the upper triangular piece of nodematrix inside the loops (for which you can use nested for loops) then make nodematrix symmetric using triu.
M1 = triu(magic(4))
M2 = M1 + triu(M1, 1).'
But since I suspect this is part of a homework assignment I'll leave it at that hint.
Emma Sellers
Emma Sellers 2019년 11월 5일
That worked to get numbers! Can you tell me how to fix it so it doesnt ask about the diagonal? I.e. I don't want (1,1), (2,2), (3,3) to change..
KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 11월 5일
Thank you @Steven

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

2019년 11월 5일

댓글:

2019년 11월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by