How to put word in the matlab function?

6 visualizaciones (últimos 30 días)
Xuejian Niu
Xuejian Niu el 31 de Mzo. de 2022
Comentada: Star Strider el 31 de Mzo. de 2022
function [A,B] = spec_convert(C,D,typein,typeout)
% typein: 'abs' or 'rel' or 'ana'
% typeout: 'abs' or 'rel' or 'ana'
% C, D: input specifications
% A, B: output specifications
%
% Enter your code below.
if typein == abs && typeout == abs
A = C;
B = D;
elseif typein == abs && typeout == rel
A = -20*log10((1-C)/(1+C));
B = -20*log10(D/(1+C));
elseif typein == abs && typeout == ana
Rp = -20*log10((1-C)/(1+C));;
As = -20*log10(D/(1+C));
elseif typein == rel && typeout == rel
A = C;
B = D;
elseif typein ==rel && typeout == abs
K = 10^(C/20);
d1 = (K-1)/(K+1);
d2 = (1+d1)*(10^(-D/20));
elseif typein == rel && typeout == ana
e = sqrt((10^(-0.1*C))-1);
A = 10^(0.05*D)
end
end

Respuestas (1)

Star Strider
Star Strider el 31 de Mzo. de 2022
Use the strcmp or strcmpi function to compare character arrays:
if strcmp(typein,'abs') && strcmp(typeout,'abs')
Do this similarly for the other tests.
.
  2 comentarios
Xuejian Niu
Xuejian Niu el 31 de Mzo. de 2022
ty
Star Strider
Star Strider el 31 de Mzo. de 2022
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

Iniciar sesión para comentar.

Categorías

Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by