Apply operation to each element of an array
202 次查看(过去 30 天)
显示 更早的评论
I have an array of numbers x1, x2, x3.... I want to obtain an array of numbers y1, y2, y3... such that yi = ceil((3/xi)^2). Is there a way to do this in one line of code without a for loop? I could do it with a for loop but I feel like I should be able to just apply the operation elementwise in a one line command.
Something like
Y = ciel((3/X)^2))
but of course that is not allowed
0 个评论
采纳的回答
Fabio Freschi
2019-11-15
编辑:Fabio Freschi
2019-11-15
You should use element-wise operations
In your case
Y = ceil((3./X).^2))
更多回答(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!