Calling a function multiple times in a for loop.

조회 수: 6 (최근 30일)
Waseem AL Aqqad
Waseem AL Aqqad 2020년 10월 21일
댓글: Waseem AL Aqqad 2020년 10월 21일
Hi,
I'm calling my function
function psiA=test_M(rmv)
multiple times, and I'm passing different input arguments each time.
rmv=[1 2 4 5 7 8];
psi=zeros(1,length(rmv));
for k = 1 :length(rmv)
psi=test_M(rmv(k));
end
The size of the output in each iteration should be 1x1, and at the end of for loop, it should be a vector of size 1x6.
In each iteration the output of previous iteration is set to zero, I don't know why.
Below is the last line of my function
psiA(1,rmv)= sizesB(1)/Nodes;
Your help would be greatly appreciated!

채택된 답변

Walter Roberson
Walter Roberson 2020년 10월 21일
psi(k) = test_M(rmv(k));
  댓글 수: 2
Waseem AL Aqqad
Waseem AL Aqqad 2020년 10월 21일
Thanks, Mr. Roberson!
I tried this previously but I got this error
Unable to perform assignment because the left and right sides have a different number of elements.
Waseem AL Aqqad
Waseem AL Aqqad 2020년 10월 21일
In my function,
I should have written
psiA= sizesB(1)/Nodes;
instead of
psiA(1,rmv)= sizesB(1)/Nodes;
Thanks again!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by