I can't create a graph using matlab...

1 visualización (últimos 30 días)
Marc Capafons Garcia
Marc Capafons Garcia el 2 de Abr. de 2020
Comentada: Vinod el 13 de Abr. de 2020
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.
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

Steven Lord
Steven Lord el 2 de Abr. de 2020
When I tried to read the data from that channel the output data was the 0-by-0 empty.
The channelInfo output states that this channel was:
Created: 17-Jun-2019 21:16:23
Updated: 28-Oct-2019 14:39:30
so it looks like there's just no data for your range. When I used a larger and later range:
dateRange = [datetime('March 7, 2019'),datetime('March 13, 2020')];
I was able to get some data.
  6 comentarios
Steven Lord
Steven Lord el 13 de Abr. de 2020
Are you running this on MATLAB Online (which I believe has a limit on how long your code can run) or on MATLAB running on your desktop?
Try reducing the range of data you're processing and measure how long the processing takes. Use that data to get a rough extrapolation for how long processing your whole data set is likely to take.
If it's too long for MATLAB Online, you may need to switch to running on your desktop. Or you may need to find a different approach (maybe converting your data from an array to a timetable and using functions like retime or groupsummary to process each hour's data.)
Vinod
Vinod el 13 de Abr. de 2020
If you are using a Free, Student or Home license of ThingSpeak, your MATLAB code execution needs to be completed within 20 seconds. With a Standard license or an Academic license, you can execute MATLAB code on ThingSpeak for up to 60 seconds. See this page for licensing options.
If you have access to MATLAB Online or MATLAB on your desktop, you can profile your code to see which lines of code are taking time to try and optimize it for quick execution.

Iniciar sesión para comentar.

Más respuestas (0)

Comunidades de usuarios

Más respuestas en  ThingSpeak Community

Categorías

Más información sobre Visualize Data en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by