필터 지우기
필터 지우기

for-loop to create vector

조회 수: 4 (최근 30일)
Slane Haltine
Slane Haltine 2020년 10월 15일
댓글: Ameer Hamza 2020년 10월 16일
I am just learning for end loops.
I am trying to create a for end loops that can find the maximum value of each column of a matrix and store the results in a single vector.
I have ankle moment data and I want to identify the maximum moment of each stride (column in the data) using a for-loop to store the results in a vector.

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 10월 15일
편집: Ameer Hamza 2020년 10월 15일
Since you insist on using for-loop
M; % your matrix
n = size(M, 2); % number of columns
max_vals = zeros(1, n);
for i = 1:n
max_vals(i) = max(M(:,i));
end
Without for-loops
max_vals = max(M);
  댓글 수: 15
Slane Haltine
Slane Haltine 2020년 10월 15일
Awesome, thank you!
Ameer Hamza
Ameer Hamza 2020년 10월 16일
Note that If you just want to conver a row vector to a column vector then you can even use
max_column = max_column(:);
% or
max_column = max_column.'; % in this case, max_column must be a row vector

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by