How to solve this error "Operands to the || and && operators must be convertible to logical scalar values." ?

1 次查看(过去 30 天)
I want matlab to display the new y values but i keep getting the error.
y = [5000 17000 25000 75000];
if y < 10000
ty = 200;
elseif y > 10000 && y < 20000
ty = (200 + 0.1*(y - 10000));
elseif y > 20000 && y < 50000
ty = (1200 + 0.15*(y - 20000));
elseif y > 50000
ty = (5700 + 0.25*(y - 50000));
end

采纳的回答

KSSV
KSSV 2020-4-9
编辑:KSSV 2020-4-9
Your input should be a scalar..i.e y should be a scalar.
y_val = [5000 17000 25000 75000];
ty = zeros(size(y_val)) ;
for i = 1:length(y_val)
y = y_val(i) ;
if y < 10000
ty(i) = 200;
elseif y > 10000 && y < 20000
ty(i) = (200 + 0.1*(y - 10000));
elseif y > 20000 && y < 50000
ty(i) = (1200 + 0.15*(y - 20000));
elseif y > 50000
ty(i) = (5700 + 0.25*(y - 50000));
end
end
  3 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Multirate Signal Processing 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by