problem output of two loops
조회 수: 5 (최근 30일)
이전 댓글 표시
Hi!
I have twoo loops and i want to get theresult: Example
% for i=1:2
X(i)% X data to be loaded
for k=1:6
f= a function wich dependent on X(i) and other parameter
end
end
how could i get the output f for all X(i)?
Thank you!
댓글 수: 0
채택된 답변
Image Analyst
2012년 11월 21일
In the loop, use a 2D array for f which depends on i and k:
for k = 1 : 6
for i = 1 : length(X)
f(k, i) = the function that takes k and X(i) as input arguments
end % of loop over i
end % of loop over k
Or, just in case you got your k and i mixed up, you can do it over only k
for k = 1 : 6
f(k) = the function that takes k and X(k) as input arguments
end % of loop over k
Use whichever way you were thinking of.
댓글 수: 0
추가 답변 (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!