How can we write the for loop for accessing a table data?
조회 수: 2 (최근 30일)
이전 댓글 표시
i want to perform operations on a table data, for that i need to access data of table using its index and again updated value of that index data should be stored at the same position.
- * For Example: * * A table having 3 columns and 10 rows, i have written following code but its not working,
for i=1:10
for j=1:3
if j==1
x=x<=5
else if j==2
x=x<=15
else
x=x<=25
end
end
end
Please correct my code......
채택된 답변
Walter Roberson
2014년 1월 28일
for i=1:10
for j=1:3
if j==1
x(i,j) = x(i,j) <= 5
else if j==2
x(i,j) = x(i,j) <= 15
else
x(i,j) = x(i,j) <= 25
end
end
end
추가 답변 (1개)
Amit
2014년 1월 28일
If Walter's interpretation is correct, then you do not need so many loops. A single loop approach will be:
A = [5 15 25];
for j = 1:3
x(:,j) = x(:,j) <= A(j);
end
or no loop way:
x = x <= repmat([5 15 25],10,1);
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!