难以从url的数据webread绘制图形



我正在进行的活动包括从url中读取天气预报数据并将其绘制为图形。我正在绘制压力、温度、湿度和风速。压力和温度图绘制得很好,但湿度和风速根本没有绘制出来。我不确定我的for循环是否有问题或其他问题。这是我的代码:

%% Project API
clear;
clc;
api = 'https://api.openweathermap.org/data/2.5/onecall/timemachine?lat={lat}&lon={lon}&dt={time}&appid={b5904b7602f68fcca1d8886d36b36c4e}';
%api = 'api.openweathermap.org/data/2.5/forecast?q=London&appid=b5904b7602f68fcca1d8886d36b36c4e';
url = 'http://api.openweathermap.org/data/2.5/forecast?q=London&APPID=b5904b7602f68fcca1d8886d36b36c4e';
London_Data = webread(url);
London_Data.list{1, 1}.main.pressure;
London_Data.list{1,1}.main.humidity;
London_Data.list{1, 1}.dt_txt;


%day = [Data.list{1, 1}.dt_txt:Data.list{40, 1}.dt_txt];
%pressure = [Data.list{1, 1}.main.pressure:Data.list{3, 1}.main.pressure];

%Pressure
for i = 1:40
%i = i+1;
figure(1)
plot([i+1 , London_Data.list{1, 1}.main.pressure : London_Data.list{40, 1}.main.pressure]);
title('Pressure Forecast In London')
xlabel('Days')
ylabel('Pressure[hPa]')

end
%Temperature
for i=0:1:40  
figure(2)
plot([i+1 , London_Data.list{1, 1}.main.temp]);
i = i+1;
title('Temperature Forecast In London')
xlabel('Days')
ylabel('Temperature[C]')
end
%Humidty
for i = 0;1:40
figure(3)
plot([i+1 , London_Data.list{1, 1}.main.humidity : London_Data.list{40, 1}.main.humidity]);
%i = i + 1
title('Humidity Forecast In London')
xlabel('Days')
ylabel('Humidity[Units]')
end
%Wind Speed
for i = 1:40
%i = i+1;
figure(4)
plot([i+1 ,London_Data.list{1, 1}.wind.speed : London_Data.list{40, 1}.wind.speed]);
title('Wind Speed Forecast In London')
xlabel('Days')
ylabel('Wind Speed[m/s]')

end

您的代码有一些问题,如果您对我更改它的方式有任何疑问,请告诉我。

%% Project API
clear;
clc;
api = 'https://api.openweathermap.org/data/2.5/onecall/timemachine?lat={lat}&lon={lon}&dt={time}&appid={b5904b7602f68fcca1d8886d36b36c4e}';
%api = 'api.openweathermap.org/data/2.5/forecast?q=London&appid=b5904b7602f68fcca1d8886d36b36c4e';
url = 'http://api.openweathermap.org/data/2.5/forecast?q=London&APPID=b5904b7602f68fcca1d8886d36b36c4e';
London_Data = webread(url);
len = size(London_Data.list,1);
%Pre-allocates array size (can be skipped)
P = zeros(1,len);
T = zeros(1,len);
Hum = zeros(1,len);
V = zeros(1,len);
%Puts the data in arrays
for i = 1:len
P(i) = [London_Data.list{i, 1}.main.pressure];
T(i) = [London_Data.list{i, 1}.main.temp];
Hum(i) = [London_Data.list{i, 1}.main.humidity];
V(i) = [London_Data.list{i, 1}.wind.speed];
end
%Pressure
figure(1)
plot(1:len, P)
title('Pressure Forecast In London')
xlabel('Days')
ylabel('Pressure[hPa]')
%Temperature
figure(2)
plot(1:len, T)
title('Temperature Forecast In London')
xlabel('Days')
ylabel('Temperature[C]')
%Humidty
figure(3)
plot(1:len, Hum)
title('Humidity Forecast In London')
xlabel('Days')
ylabel('Humidity[Units]')
%Wind Speed
figure(4)
plot(1:len, V)
title('Wind Speed Forecast In London')
xlabel('Days')
ylabel('Wind Speed[m/s]')

相关内容

  • 没有找到相关文章