Info
此问题已关闭。 请重新打开它进行编辑或回答。
How to subtract from a vector, have it return a value of zero if the answer is less than zero, and then tell me how much was subtracted?
1 次查看(过去 30 天)
显示 更早的评论
I essentially need to write a function like this:
x=[1, 2 3]
y= 2
x(1) - y
if x(1)<0
totalsubtracted = y +x(1)
x(1)=0
else
totalsubtracted = x(1)-y
end
But without conditionals. How do I do this?
0 个评论
回答(1 个)
madhan ravi
2020-9-15
totalsubtracted = (x(1) < 0) * (y + x(1)) + (x(1) > 0) * (- y + x(1)) % ?
8 个评论
madhan ravi
2020-9-15
Ok ,so wait for the response. Don’t ask the same question a billion times before responding here.
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!