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.

 Respuesta aceptada

Star Strider
Star Strider el 30 de Mzo. de 2015
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 comentarios

Cryptik
Cryptik el 30 de Mzo. de 2015
Yes. You, sir, are a life saver. Thank you!
Star Strider
Star Strider el 30 de Mzo. de 2015
My pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Specialized Power Systems en Centro de ayuda y File Exchange.

Preguntada:

el 30 de Mzo. de 2015

Comentada:

el 30 de Mzo. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by