modify a row of an array within a function
조회 수: 28 (최근 30일)
이전 댓글 표시
I have a 2 dimensional array arr and at various places i want to replace the ii-th row.
So I would like to write a function
function arr = replace(arr, ii)
and call that, e.g. in a loop but also with fixed ii.
My problem is that i fear that all of arr is copied then.
I just want a passed by reference and replace the row.
Is this feasable??
댓글 수: 1
Stephen23
2021년 5월 18일
"My problem is that i fear that all of arr is copied then."
Have you checked this?
답변 (2개)
KSSV
2021년 5월 18일
If a is an array of size m*n, you can repalce i'th row with a row matrix b of size 1*n using:
a(i,:) = b ;
James Tursa
2021년 5월 18일
편집: James Tursa
2021년 5월 18일
This can sometimes be done inplace depending on how you write the function and how you call the function. One requirement is your function needs to be called from within another function (easy to do). Another requirement is that your variable can't be shared with another variable (not easy to guarantee unfortunately). See this blog:
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Package MATLAB Functions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!