turning the loop answer into a vector

조회 수: 1 (최근 30일)
Michelangelo Cannistraro
Michelangelo Cannistraro 2022년 11월 29일
댓글: Michelangelo Cannistraro 2022년 11월 30일
load data_matrix.mat
data=SECTION_L;
data(:,1:3)=[];
row=9;
cleanup=data([1 2 3 row],:);
for i = 1975:2016
for j=1:12
averageM={mean(cleanup(4,cleanup(1,:)==i & cleanup(2,:)==j))}
end
end
This script gives me constant 1x1 arrays. This script takes temperatures from each day from each month from each year from 1975 to 2016. The script gives the averages from each month but doesnt put it in a vector, but makes multiple 1x1 arrays and i do not know how to put all the averages into one big vector.

채택된 답변

David Hill
David Hill 2022년 11월 29일
load data_matrix.mat
data=SECTION_L;
data(:,1:3)=[];
row=9;
cleanup=data([1 2 3 row],:);
c=1;
for i = 1975:2016
for j=1:12
averageM(c)={mean(cleanup(4,cleanup(1,:)==i & cleanup(2,:)==j))};%index into averageM
c=c+1;
end
end
  댓글 수: 3
Walter Roberson
Walter Roberson 2022년 11월 30일
We do not know what class(SECTION_L) is. Also, it is possible that you had an existing numeric averageM in your workspace that is interfering with the assignment.
Michelangelo Cannistraro
Michelangelo Cannistraro 2022년 11월 30일
I changed the name of the numeric and it worked. Thank you, both of you.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by