How to solve this error "Operands to the || and && operators must be convertible to logical scalar values." ?
2 次查看(过去 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
0 个评论
采纳的回答
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
更多回答(0 个)
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!