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!
Star Strider
Star Strider 2015 年 3 月 30 日
My pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeSpecialized 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