Saving data from a for loop (new-ish to MATLAB!)
Show older comments
I have the following for loop to get barometric pressure data from the NOAA tide buoy in Bar Harbor, ME (NOAA only provides data in one month increments and I need data for three months, hence the loop)
mn_start=9; %month to start
dd_start=11; %day to start
date_BH=[];baro_BH=[];%initializing datenum and baro variables
num_mnths=3; %number of consective months to loop - note coded to just to yr=2022
for i=1:num_mnths;
begin_date=['2022' num2str(mn_start+i-1,'%02.f') num2str(dd_start)];
end_date=['2022' num2str(mn_start+i,'%02.f') num2str(dd_start-1)];
NOAAurl_Baro=['https://api.tidesandcurrents.noaa.gov/api/prod/datagetter?' ...
'begin_date=', begin_date, '&end_date=' end_date , '&station=8413320&'...
'product=air_pressure&datum=MSL&time_zone=lst_ldt&units=metric&format=csv'];
datatable=webread(NOAAurl_Baro);%getting waterlevel data from NOAA
date_BH=[date_BH table2array(datatable(:,1))'];%serial date number
baro_BH=[baro_BH table2array(datatable(:,2))'];%barometric pressure (mbars); datenum same as WL
end
When the loop closes, I only have data saved from the final iteration. How can I save data from every iteration? Thank you!
Accepted Answer
More Answers (0)
Categories
Find more on Financial Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!