フィルターのクリア

for-loop to create vector

6 ビュー (過去 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 Center および File ExchangeLogical についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by