# Using a loop to calculate max values

7 ビュー (過去 30 日間)
Jordan Rosales 2021 年 1 月 31 日
コメント済み: madhan ravi 2021 年 1 月 31 日
For a homework problem I have a structure with one field which is a 40x12 table. For this problem I am asked to find the maximum values of each row and plot them vs the row number. I am assuming they do not want me to do this manually as it would take a long time to seperate and calculate the maximums for each row individually. I will also need to do the same for the row minimums. I was thinking of using a for loop but I cannot seem to figure out how to set it up.
What I was thinking:
for i=1:40
max(temp(i,:))
end
When doing this I get an error saying max is not appropriate the first argument must be numeric or logical.

サインインしてコメントする。

### 回答 (2 件)

madhan ravi 2021 年 1 月 31 日
You were almost close.
plot(max(temp.temp, [], 2))
##### 0 件のコメント-2 件の古いコメントを表示-2 件の古いコメントを非表示

サインインしてコメントする。

andre con 2021 年 1 月 31 日
Hello Jordan,
I think that your variable "temp" has not been appropriately defined because your code is OK. Below, I have written a simple code using your idea, and it works well.
clc; clear all; close all;
A = [11 2 3;4 15 6;7 8 9]
for j=1:3
maxA_row(j) = max(A(:,j));
end
maxA_row
##### 1 件のコメント-1 件の古いコメントを表示-1 件の古いコメントを非表示
madhan ravi 2021 年 1 月 31 日
maxA_row(j) = max(A(j, :)); % you have it the other way around

サインインしてコメントする。

### カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

### Community Treasure Hunt

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

Start Hunting!

Translated by