How get one element of a vector one by one in each iteration of for loop?

조회 수: 3 (최근 30일)
Neda
Neda 2017년 8월 11일
댓글: Sangeetha Jayaprakash 2017년 8월 15일
rowKernel(1) is just getting one element from rowKernel which I load it before. I need to get all element from rowKernel file, but one by one in each iteration, means each ROW in each iteration should include one elements. Could you please let me know how can I write the code by this way. Now, I have in each iteration just first value in rowKernel and colKernel, but I need all of them which they are 180 values, but as I said I need them one by one in each iteration. Thank you.
load rowKernel
load colKernel
row = 0;
for ROW = rowKernel(1)
row = row + 1;
BM.KernelY(row,1) = ROW;
col = 0;
for COL = colKernel(1)
col = col + 1;
BM.KernelX(col,1) = COL;
BM.KernelY_Global (ROW,COL) = row;
BM.KernelX_Global (ROW,COL) = col;
end
end
  댓글 수: 3
Neda
Neda 2017년 8월 11일
As I said rowKernel and colKernel are vectors, and I need one elements back in each iteration, for example, If I write like below, the ROW result in each iteration is a vector, but I need one scalar value back to me in each iteration. thanks
for ROW = rowKernel(1:180)
row = row + 1;
BM.KernelY(row,1) = ROW;
Sangeetha Jayaprakash
Sangeetha Jayaprakash 2017년 8월 15일
I understand that "rowKernel" is a vector of size N and you would like to get one element from that vector in each iteration.
This can be done as follows:
for r_idx = 1:N
element = rowKernel(r_idx);
end

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

답변 (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