필터 지우기
필터 지우기

Creating an array for Multiple variables?

조회 수: 4 (최근 30일)
Chris  Lambrecht
Chris Lambrecht 2015년 9월 16일
답변: Walter Roberson 2015년 9월 17일
I am given a large group of data that involves months and years and was looking for a quick way to process this. It is easiest to do this using two for loops but I need to retain that information. I have tried using {} but that will only let me use one of the loops. So far, my code is:
for mo=1:12
for year=2005:2015
[dttm,timemin,wnddatenum,wndspeed,wnddir,pres,temp]= ...
RdNCDCData(filename,mo,yr,iminsamp);
end
end
How would I be able to get an array giving the month and year as something like [1,2005] for the variable?

채택된 답변

Walter Roberson
Walter Roberson 2015년 9월 17일
yearno = 2005:2015;
for mo = 1:12
for yearidx = 1 : length(yearno)
year = yearno(yearidx);
[dttm{mo,yearidx}, timemin{mo,yearidx}, wnddatenum{mo,yearidx}, wndspeed{mo,yearidx}, wnddir{mo,yearidx}, pres{mo,yearidx}, temp{mo,yearidx}] = RdNCDCData(filename, mo, year, iminsamp);
end
end
Afterwards, to find a given year,
yearidx = find(yearno == 2009); %for example
and then you can access the variables by month and yearidx
temp2009 = temp(:,find(yearno == 2009)); %would be all 12 months for 2009

추가 답변 (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