Git Product home page Git Product logo

weather's Introduction

Weather analysis

Open in MATLAB Online

Open the app in focus mode: https://matlab.mathworks.com/open/github/v1?repo=yanndebray/weather&file=weather.mlapp&focus=true

Open the live script in focus mode: https://matlab.mathworks.com/open/github/v1?repo=yanndebray/weather&file=livescript.mlx&focus=true

Prepare data

apiKey ="b1b15e88fa797225412429c1c50c122a1";

% Define the location for which you want the weather forecast
cityName = "Muenchen"; 
countryCode = "DE";

% Create the URL for the API call
url = sprintf("http://samples.openweathermap.org/data/2.5/forecast?q=%s,%s&appid=%s", cityName, countryCode, apiKey);

% Send the web request to the OpenWeatherMap API
response = webread(url);

% Assuming "response" is the struct obtained from the OpenWeatherMap API
data = parseForecast(response.list);
data = struct2table(data)
date temperature weather clouds wind details
1 16-Feb-2017 12:00:00 286.6700 'Clear' 0 1.8100 'clear sky'
2 16-Feb-2017 15:00:00 285.6600 'Clear' 0 1.5900 'clear sky'
3 16-Feb-2017 18:00:00 277.0500 'Clear' 0 1.4100 'clear sky'
4 16-Feb-2017 21:00:00 272.7800 'Clear' 0 2.2400 'clear sky'
5 17-Feb-2017 00:00:00 273.3410 'Clouds' 76 3.5900 'broken clouds'
6 17-Feb-2017 03:00:00 275.5680 'Rain' 76 3.7700 'light rain'
7 17-Feb-2017 06:00:00 276.4780 'Rain' 92 3.8100 'moderate rain'
8 17-Feb-2017 09:00:00 276.6700 'Rain' 64 2.6000 'light rain'
9 17-Feb-2017 12:00:00 278.2530 'Rain' 92 3.1700 'light rain'
10 17-Feb-2017 15:00:00 276.4550 'Rain' 92 3.2100 'light rain'
11 17-Feb-2017 18:00:00 275.6390 'Rain' 88 3.1700 'light rain'
12 17-Feb-2017 21:00:00 275.4590 'Rain' 88 3.7100 'light rain'
13 18-Feb-2017 00:00:00 275.0350 'Rain' 92 3.5600 'light rain'
14 18-Feb-2017 03:00:00 274.9650 'Rain' 88 2.6600 'light rain'

Modeling

n = 3;
X = (1:36);
y = data.temperature;
p = polyfit(X,y,n);
y1 = polyval(p,X);
plot(X,y,X,y1)

figure_0.png

Helper function

function forecastData = parseForecast(responseList)
    % Initialize an array of structs to hold the parsed forecast data
    forecastData = struct("date", {}, "temperature", {}, "weather", {}, "clouds", {}, "wind", {}, "details", {});

    % Loop through each entry in the responseList cell array
    for i = 1:length(responseList)
        % Get the current forecast struct
        forecastStruct = responseList{i};

        % Extract the date and time of the forecast
        forecastData(i).date = datetime(forecastStruct.dt, "ConvertFrom", "posixtime");

        % Extract main forecast data like temperature
        forecastData(i).temperature = forecastStruct.main.temp;

        % Extract weather conditions
        forecastData(i).weather = forecastStruct.weather(1).main;

        % Extract cloud data
        forecastData(i).clouds = forecastStruct.clouds.all;

        % Extract wind data
        forecastData(i).wind = forecastStruct.wind.speed;

        % Extract additional details if needed
        forecastData(i).details = forecastStruct.weather(1).description;
    end
end

weather's People

Contributors

yanndebray avatar

Watchers

Lucian avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.