nested for loop with different variable name
조회 수: 2 (최근 30일)
이전 댓글 표시
S is cell array of size 994*1 and each cell size in it is 24*24, price3(size 1*24), Bita(size 1*24), CONS_T3(size 1*24), I want to write Py1...Py994 like following this, how can we write in a loop....
% Py for S{1,1} its all rows
for i=1:24
Py1(i) = -S{1,1}(i,:)*(price3 + Bita.*(CONS_T3-S{1,1}(i,:))./100)';
end
% Py2 for S{2,1} for its all rows
for i=1:24
Py2(i) = -S{2,1}(i,:)*(price3 + Bita.*(CONS_T3-S{2,1}(i,:))./100)';
end
and Py3,Py4 ....so on.
댓글 수: 1
채택된 답변
Walter Roberson
2018년 1월 12일
댓글 수: 2
Stephen23
2018년 1월 12일
편집: Stephen23
2018년 1월 12일
" find out Py1 and store it and for next 24 rows find out Py2 and from next 24 rows find out Py3 and so on "
That is exactly how beginners write slow, buggy, insecure, obfuscated, complex code that is hard to debug. Your data is already conveniently in one array, which efficient and simple to use with vectorized code, access within loops, access using indexing, or by trivially passing to functions. You want to replace this simple code with something complex, buggy, and slow (because that is what magically accessing variable names means, no matter what method you use). Can you please explain why you suddenly need to make your code slow and inefficient?
추가 답변 (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!