# How do I put all the Outputs from the iterations of a For Loop into a Row Vector?

조회 수: 7 (최근 30일)
Jeofrey Kaneida Camarse . 2022년 4월 26일
답변: Mahmoud Ashraf . 2022년 4월 26일
I want to take the maximum value of every row in the matrix A and put them into a vector assigned to variable C. Here's what I have done so far:
A = [1 2 3 4; 8 7 6 5; 9 10 11 12]
numrows = height(A)
for x = 1:numrows
B = max(A(x,:))
end
This is what C should be:
C = [4 8 12]
I have no idea where to start for C. All I know is it is not C = B even if outside or inside the loop.
If there is a name of a topic that deals with putting outputs from a for loop into an array, I would greatly appreciate being referred to a link where I can read about it. Other answers that do not involve loops are also OK. Many thanks :)

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

### 채택된 답변

Walter Roberson 2022년 4월 26일
Assign to B(x) instead of B

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

### 추가 답변 (1개)

Mahmoud Ashraf 2022년 4월 26일
A = [1 2 3 4; 8 7 6 5; 9 10 11 12]
numrows = height(A)
for x = 1:numrows
B = max(A(x,:))
c(1,x)=B
end

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

### 카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

R2022a

### Community Treasure Hunt

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

Start Hunting!