MATLAB Answers

graphing data using webread

2 views (last 30 days)
Iman Walji
Iman Walji on 26 Nov 2020
Commented: Iman Walji on 27 Nov 2020
Hello I am trying to graph the main data, average and standard deviation of data using hydrometric online data. I have come up with the following code to plot this data.
station_id = ["02DD016", "02HA014", "02HC030", "02HC024"];
titles = ["FRENCH RIVER AT PORTAGE DAM", "REDHILL CREEK AT HAMILTON",...
"ETOBICOKE CREEK BELOW QUEEN ELIZABETH HIGHWAY","DON RIVER AT TODMORDEN"];
base_url = 'dd.weather.gc.ca/hydrometric/csv/';
province = 'ON';
frequency = 'daily';
file_type = 'csv';
for z = 1:4
my_url = strcat('https://', base_url, province, '/', frequency, '/', ...
province, '_', station_id(z), ...
'_', frequency, '_hydrometric.', file_type);
gauge_data = webread(my_url);
depth_data = gauge_data.WaterLevel_NiveauD_eau_m_.';
depth_data(find(isnan(depth_data)))=[];
y = depth_data;
x = 1:1:length(y);
avg_y_scalar = mean(y);
avg_y_vector = avg_y_scalar *...
ones(1,length(y));
std_y = std(y);
y_plus = y + std_y;
y_minus = y - std_y;
y_minus_reverse = fliplr(y_minus);
figure(1)
subplot (2,2,z)
% plot the data and average
plot(x,y,x,avg_y_vector);
% plot std deviation shape
patch([1:1:length(y)...
length(y):-1:1],...
[y_plus y_minus_reverse],...
'b',...
'facealpha',0.05,...% fill colour
'edgecolor','r',...
'edgealpha',0.05) % edge colour
% Legend, Title, axis labels.
legend('original data',...
'average values',...
'standard deviation');
title(titles(z));
xlabel('Historical Daily Water Level [Day]');
ylabel('Water Level [m]');
end
My first graph is supposed to look like this
but instead looks like this
and my other three graphs look fine so I do not know what the problem is

  0 Comments

Sign in to comment.

Accepted Answer

VBBV
VBBV on 26 Nov 2020
figure(1)
subplot (2,2,z)
if z == 1
% plot the data and average
plot(x(1:100:end),y(1:100:end),x(1:100:end),avg_y_vector(1:100:end));
%plot(x,y,x,avg_y_vector);
patch([1:1:length(y)...
length(y):-1:1],...
[y_plus y_minus_reverse],...
'b',...
'facealpha',0.05,...% fill colour
'edgecolor','r',...
'edgealpha',0.004) % edge colour
else
plot(x,y,x,avg_y_vector);
patch([1:1:length(y)...
length(y):-1:1],...
[y_plus y_minus_reverse],...
'b',...
'facealpha',0.05,...% fill colour
'edgecolor','r',...
'edgealpha',0.05) % edge colour
% Legend, Title, axis labels.
end
For first subplot, it seems there are many data points. Use a condition like above with edgecolor having a small value

  5 Comments

Show 2 older comments
VBBV
VBBV on 26 Nov 2020
May be they have changed the webdata for first plot. That's why it's different.
VBBV
VBBV on 26 Nov 2020
Online data available for first plot seems to have changed than the one you're supposed to get.
Iman Walji
Iman Walji on 27 Nov 2020
I guess so because I do not know why the code would only affect the first graph

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!