필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
Hunter Nau
Hunter Nau 2022년 4월 19일
답변: Adam Danz 2022년 4월 19일
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