Matrix won't display while inside "if" statement

% This script uses the function, respower, to test several pre-computed % test cases of equivalent resistance and power rating, and it compares the % functional values with actual values.
A = [4 5 3];
B = [200 3 40];
Req = (1/((1/4)+(1/5)+(1/3)));
Peq = 34;
total = respower(A,B);
if (total ~= [Req,Peq])
fprintf('Test values used for resistors: %d ',A);
fprintf('\n')
fprintf('Test values used for power ratings: %d ',B);
fprintf('\n');
fprintf('The actual result for equivalent resistance (left) and equivalent power rating (right) is: %f',[Req,Peq]);
fprintf('\n');
fprintf('The expected result for equivalent resistance in ohms (left) and equivalent power rating in watts (right) is: %f',total);
fprintf('\n');
end
The respower function works correctly. This test is for when the pre-computed equivalent resistance and power rating (test values) does not agree with the function. For some reason, I get absolutely no output from this code. Any help would be greatly appreciated.

 채택된 답변

Star Strider
Star Strider 2015년 3월 30일

0 개 추천

The problem is comparing a scalar and a vector. If you want to test ‘total’ against ‘Req’ or ‘Peq’ as a vector, use any.
For example:
A = 1;
B = 2;
C = 1;
if C ~= [A,B]
fprintf('Test #1 Successful!\n\n')
end
if any(C ~= [A,B])
fprintf('Test #2 Successful!\n\n')
end
Does this do what you want?

댓글 수: 2

Cryptik
Cryptik 2015년 3월 30일
Yes. You, sir, are a life saver. Thank you!
My pleasure!

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

추가 답변 (0개)

카테고리

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

질문:

2015년 3월 30일

댓글:

2015년 3월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by