Using for loop to find values greater than a number in each column.

6 次查看(过去 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
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

回答(1 个)

Adam Danz
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.

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by