I can't create a graph using matlab...
Mostrar comentarios más antiguos
Hello! I am trying to create a 3d graph of these that have to be displayed and we got this error when I try to save and execute the matlab code ...
I attach the error, the complete matlab code and the web from where the information was taken.
Website of the information: https://es.mathworks.com/matlabcentral/mlc-downloads/downloads/submissions/56910/versions/4/previews/html/ThingSpeakWeatherStation.html#2
Graph I want to create:

Matlab code:
% Channel ID to read data from
readChannelID = 803557;
% Specify date range
dateRange = [datetime('March 7, 2016'),datetime('March 13, 2016')];
% Read data including the timestamp, and channel information.
[data,time,channelInfo] = thingSpeakRead(readChannelID,'Fields',1:7,...
'DateRange',dateRange);
% Create variables to store different sorts of data
temperatureData = data(:,1);
humidityData = data(:,2);
pressureData = data(:,3);
rainData = data(:,4);
windSpeedData = data(:,5);
windGustData = data(:,6);
windDirectionData = data(:,7);
% Create a day range vector
dayRange = day(dateRange(1):dateRange(2));
% Pre-allocate matrix
weatherData = zeros(length(dayRange),24);
% Generate temperature 3D bar chart
% Get temperature per whole clock for each day
for m = 1:length(dayRange) % Loop over all days
for n = 1:24 % Loop over 24 hours
if any(day(time)==dayRange(m) & hour(time)==n); % Check if data exist for this specific time
hourlyData = temperatureData((day(time)==dayRange(m) & hour(time)==n)); % Pull out the hourly temperature from the matrix
weatherData(m,n) = hourlyData(1); % Assign the temperature at the time closest to the whole clock
end
end
end
% Plot
figure
h = bar3(datenum(dateRange(1):dateRange(2)), weatherData);
for k = 1:length(h) % Change the face color for each bar
h(k).CData = h(k).ZData;
h(k).FaceColor = 'interp';
end
title('Temperature Distribution')
xlabel('Hour of Day')
ylabel('Date')
datetick('y','mmm dd') % Change the Y-Tick to display specified date format
ax = gca;
ax.XTick = 1:24; % Change the X-Tick to 24 hours
ax.YTickLabelRotation = 30; % Rotate label for better display
colorbar % Add a color bar to indicate the scaling of color
% Generate humidity 3D bar chart
% Get humidity per whole clock for each day
for m = 1:length(dayRange) % Loop over all days
for n = 1:24 % Loop over 24 hours
if any(day(time)==dayRange(m) & hour(time)==n); % Check if data exist for this specific time
hourlyData = humidityData((day(time)==dayRange(m) & hour(time)==n)); % Pull out the hourly humidity from the matrix
weatherData(m,n) = hourlyData(1); % Assign the humidity at the time closest to the whole clock
end
end
end
% Plot
figure
h = bar3(datenum(dateRange(1):dateRange(2)), weatherData);
for k = 1:length(h) % Change the face color for each bar
h(k).CData = h(k).ZData;
h(k).FaceColor = 'interp';
end
title('Humidity Distribution')
xlabel('Hour of Day')
ylabel('Date')
datetick('y','mmm dd') % Change the Y-Tick to display specified date format
ax = gca;
ax.XTick = 1:24; % Change the X-Tick to 24 hours
ax.YTickLabelRotation = 30; % Rotate label for better display
colorbar % Add a color bar to indicate the scaling of color
Error we said:

I would really appreciate your help.
Thanks.
Marc
Respuesta aceptada
Más respuestas (0)
Comunidades de usuarios
Más respuestas en ThingSpeak Community
Categorías
Más información sobre Line Plots en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


