Hi All,
I want to say Hi first of all as this is my first ever post.
I am working on Matlab code which utilities a lot of "For" loops and iterations. Part of the code looks like this:
for k = 1:length(TSR_vals);
TSR(k) = TSR_vals(k);
....
....
....
end
My question is, what does TSR(k) = TSR_vals(k); represent? why is the k in brackets?
Thanks, Kacper

댓글 수: 4

KACPER PAWLOWSKI
KACPER PAWLOWSKI 2017년 9월 10일
From what I could read is that TSR will refer to element 'k' as it traverses in order in the matrix for each iteration, correct?
José-Luis
José-Luis 2017년 9월 10일
I don't understand what you mean.
You could use the debugger and look at the values of the variables during each iteration. It could help you understand.
dpb
dpb 2017년 9월 10일
편집: dpb 2017년 9월 10일
Set a breakpoint in the editor and use the debugger to step through and see...
Just one word of caution, however--*NB* the definition of length in the help for it -- it returns max(size(X)) for variable X. IF there are two dimensions in the array and the number of columns is larger than the number of rows, then the returned length will be the number of columns, not rows. Be sure you know which it is that you want, specifically.

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

답변 (1개)

Jose Marques
Jose Marques 2017년 9월 10일

0 개 추천

Hello, KACPER PAWLOWSKI. You can see the values in each iteration. After each iteration, you must press enter to continue to next value of k. At the end, the intire TSR will be print.
for k = 1:length(TSR_vals);
k
TSR_vals(k)
TSR(k) = TSR_vals(k)
pause();
end
TSR

댓글 수: 2

José-Luis
José-Luis 2017년 9월 10일
The way to go about this is to use the debugger. Say you wanted to perform an operation during debugging. That ain't gonna work if you do this.
You can resume execution by pressing any key, not just enter.
Jose Marques
Jose Marques 2017년 9월 10일
Thanks Jose Luis

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

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2017년 9월 10일

댓글:

2017년 9월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by