Using for loop to find values greater than a number in each column.
5 ビュー (過去 30 日間)
古いコメントを表示
I need to use for loop to find the temperatures that are over the mean of the matrix (65.092) for each column. I am not sure how to get it started or if I should also use an if loop inside of the for loop
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/969580/image.png)
TempSenVal=[58.3 59.2 60.2 63.0 63.3; 62.5 63.8 64.9 65.2 65.8;...
63.2 64.2 65.3 67.8 67.9; 64.0 65.1 67.8 68.2 69.1; 65.5 66.0 67.9 68.9 70.2]
%% Part B
[m,n] = size(TempSenVal) ;
M = zeros(1,n) ;
for i = 1:n
M(i) = mean(TempSenVal(:,i))
end
%% Part C
for i = 1:n
mean(TempSenVal(:))
end
%% Part D
for i=1:n
if
0 件のコメント
回答 (1 件)
Adam Danz
2022 年 4 月 19 日
It's a pitty that the homework assignment requires using a loop since this can be solved in one line of code.
y = mat > mean(mat)
Your section part B looks sufficient. Parts C and D need to be replaced.
I sounds like you need to compare the origina matrix with the vector of mean values to determine which elements of the matrix exceed the mean for each column. Use the line of code above as a hint. It will produce a logical matrix where true (1) values indicate elements that exceed the means.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!