Apply operation to each element of an array
조회 수: 162 (최근 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에서 Multidimensional Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!