apply "IF" condition to a matrix whitout loop
1 次查看(过去 30 天)
显示 更早的评论
Hi!
It is possible to use matrix operation power with "if" condition?? I want to apply "if" conditionto all value of the matrix how agree the condition with out creating a for loop or multi "if" condition
Ex: here an simple exemple I don't want to put it inside "for" loop
x = [1,2] y = [100,35]
if x>1 x = 0; else x = x .* y^2; end
In my original code "x" and "y" are huge and I try to optimize the speed
Thank you!!
0 个评论
采纳的回答
Roger Stafford
2013-11-28
That won't work with 'if'. It won't come true unless all the elements are negative. Use logical indexing.
t = x>1;
x(t) = x(t).*y(t).^2;
3 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!