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

1 view (last 30 days)
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

Accepted Answer

Steven Lord
Steven Lord on 2 Apr 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 Comments
Steven Lord
Steven Lord on 13 Apr 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 on 13 Apr 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.

Sign in to comment.

More Answers (0)

Communities

More Answers in the  ThingSpeak Community

Categories

Find more on Visualize Data in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!