Main Content

Results for

I know we have all been in that all-too-common situation of needing to inefficiently identify prime numbers using only a regular expression... and now Matt Parker from Standup Maths helpfully released a YouTube video entitled "How on Earth does ^.?$|^(..+?)\1+$ produce primes?" in which he explains a simple regular expression (aka Halloween incantation) which matches composite numbers:
Here is my first attempt using MATLAB and Matt Parker's example values:
fnh = @(n) isempty(regexp(repelem('*',n),'^.?$|^(..+?)\1+$','emptymatch'));
fnh(13)
ans = logical
1
fnh(15)
ans = logical
0
fnh(101)
ans = logical
1
fnh(1000)
ans = logical
0
Feel free to try/modify the incantation yourself. Happy Halloween!
Hi,
I don't know why really. Why is there seems a difference between daily average that calculated with .csv file that has exported directly from the channel.
and calculation with the ThingSpeak Daily Average API, there is a lot of difference at the moment.
Why does this happens, and how should I fix this issue?
Attached image file is daily average that has been retrived through the API,
And attached excel file is raw data from the channel.
Thank you.
Sundown
Sundown
Last activity on 16 Oct 2024

My Licensed avvount has expired. When I go to my expired license page, I select "Revert To Free Account", I get the following message:
Only administrators of this license are allowed to renew units on this ThingSpeak license. If you want to continue to collect data in your ThingSpeak channels, contact your license administrator.
Aren't I the license administrator? or do I need to contact someone at Thingspeak/MathWorks?
Hi, My data send to thingspeak is not received/updated for the last 6 hours on the charts and dials. All worked well till about 6 hour ago. I am using Node-red and the API Url: https://thingspeak.com
Any help please?
Greetings Gert
To solve issues around the browsers blocking 3p cookies and having different behavior across different browsers, the ThingSpeak website is now served from https://thingspeak.mathworks.com. There are no changes required from devices or users. Just log in and use the service as you always did.
I left the code unchanged, modifying only secrets.h.
I am using an ESP32-WROOM -32U
Connection to network succeeds, but ThingSpeak.writeFields fails every time, with HTTP error code 400.
The sketch I am really trying to use is loosely based on this example, accesses Time and Weather info with no problems, but ThingSpeak.writeFields fails with HTTP error code 301.
This is my first attempt to use ThingSpeak.
Is this example sketch still valid, or must I look elsewhere? Suggestions please.
Hi everyone,
I'm working on a school project where I need to send sensor data from my Arduino to a Power BI REST API using ThingsHTTP. I've been trying to get this to work, but I'm running into errors like this:
{"error":{"code":"InvalidRequest","message":"Error parsing request for dataset sobe_wowvirtualserver|a7b68fb5-533b-471f-a5da-3bdd6746ee16: Conversion error on column '<pi>pH</pi>': <pi>Input string was not in a correct format.</pi>"}}
I'm a beginner with this, and I'm not sure what I'm doing wrong. What steps should I take to resolve this issue? Also, does anyone know the correct format for an HTTP request body when sending dynamic sensor data?
This is the body format I'm trying to send to Power BI:
[
{
"pH": 98.6,
"TDS": 98.6,
"turbidity": 98.6,
"temperature": 98.6
}
]
Any advice on how to construct the HTTP body with values that change over time would be greatly appreciated! Thanks in advance!"
hope this message finds you well. I am currently working on a project involving the design and numerical simulation of metalenses using Zemax and MATLAB. The design phase involves saving phase data from the Zemax simulation, which is later used in a numerical script to generate the metalens in MATLAB.
I have a MATLAB file that contains the phase data saved from Zemax, but I am unsure of the specific method or format used to extract and save the data from Zemax. The phase data I currently have in MATLAB is as follows:
  • Phase matrix: 571 x 571 (double)
  • X data: 571 x 1 (double)
  • Y data: 571 x 1 (double)
Could you please provide guidance on:
  1. How this phase data was likely saved from Zemax into MATLAB?
  2. What steps or scripts were used to extract this information from the design, particularly the 571 x 571 phase matrix and the corresponding X and Y data?
  3. Any best practices or tools available in Zemax for exporting such data?
This information will help me reproduce the workflow and proceed with my analysis.
Thank you for your support. I look forward to your guidance.
Best regards,
Zaka
I went to perform an IoT for an automated plantation but the same error always occurs to me when I upload it to the mcu node, which is: Connection to ThingSpeak failed.
David
David
Last activity on 12 Sep 2024

In case you haven't come across it yet, @Gareth created a Jokes toolbox to get MATLAB to tell you a joke.
It's been over six years since I've written any serious MATLAB code, so I thought it would be fun to see how easily ChatGPT could help me out. While others have probably already used ChatGPT to generate MATLAB code, I didn't find any evidence of it when I searched through the ThingSpeak forum. That inspired me to post an example to get people thinking about it.
This example reads four temperature fields from the same channel and plots them on a single graph.
My ChatGPT prompt:
The prompt is pretty straightforward and essentially walks through all the elements of the chart that I wanted. It's also important to consider any filtering or "data cleansing" that should be done. Since this was my first time doing this, I decided to use an existing plot I was already familiar with as my "target state".
The prompt: "I would like you to generate some MATLAB code to create what is called a MATLAB Visualization. Its purpose will be to generate a chart of 4 fields found in a ThingSpeak channel. The ThingSpeak channel name is "Nest Nanny 2 (NN-02)" and its channel id (needed for the code) is xxxxxxx. The read api key is XXXXXXXXXXXXXXXX. The chart title should be "Nest Nanny 02 (NN-02) Todays Temperature Readings" It should plot data from 4 fields (field 3 - 6) who's names are "Surface Temp", "1/4 Temp", "3/4 Temp", and "Deep Temp". I would like the plot lines for these 4 fields to be different colors (red, orange, cyan, and blue) but on the same chart. I would like Temperature in Fahrenheit to be on the Y axis and Time on the x axis. I would like it to display the last 100 data points. I'd like to use this colororder. colororder(["#FF0000","#FFBB00","#00BBFF", "#0000FF"]) I would like the legend to be to the right of the chart, not contained within the chart. No temperature data should have a value of 50 or less and we can assume it's a sensor issue when this is observed. If a data value is 50 or less, use the value of it's nearest (in the time series) non-zero, non-negative value for that field. The data is stored in the channel as Fahrenheit and does not need to be converted from Celsius. "
Because I did this exercise using an existing plot and had a clear objective in mind, it was relatively quick to iterate four or five times with ChatGPT to refine my prompt. In just a few minutes, the generated plot almost perfectly matched my existing plot. (I xxxx'ed out the channel ID and API key before posting.) For someone who now only occasionally uses MATLAB, this approach saves time and will hopefully allow me to tap into elements of MATLAB that are now beyond my skill level and memory. ;)
ChatGPT generated MATLAB code:
% MATLAB code to create a ThingSpeak Visualization for temperature readings
% Define channel ID and Read API Key
channelID = xxxxxxx;
readAPIKey = 'XXXXXXXXXXXXXXXX';
% Number of data points to retrieve
numPoints = 100;
% Read data from the ThingSpeak channel for fields 3 to 6
[data, time] = thingSpeakRead(channelID, ...
'Fields', [3 4 5 6], ...
'NumPoints', numPoints, ...
'ReadKey', readAPIKey);
% Replace any value 50 or less with the nearest non-zero, non-negative value
for i = 1:size(data, 2)
% Identify indices where the data is 50 or less
badIndices = find(data(:,i) <= 50);
% Identify indices where the data is valid (greater than 50)
validIndices = find(data(:,i) > 50);
% Interpolate to replace bad values
if ~isempty(validIndices)
data(badIndices, i) = interp1(validIndices, data(validIndices, i), badIndices, 'linear', 'extrap');
end
end
% Plot the data
figure;
colororder(["#FF0000","#FFBB00","#00BBFF", "#0000FF"]); % Set the color order
plot(time, data(:,1), 'LineWidth', 2); hold on;
plot(time, data(:,2), 'LineWidth', 2);
plot(time, data(:,3), 'LineWidth', 2);
plot(time, data(:,4), 'LineWidth', 2);
hold off;
% Add labels and title
xlabel('Time');
ylabel('Temperature (°F)');
title('Nest Nanny 02 (NN-02) Todays Temperature Readings');
% Add legend and move it to the right of the chart
legend({'Surface Temp', '1/4 Temp', '3/4 Temp', 'Deep Temp'}, ...
'Location', 'eastoutside');
% Format the time on the x-axis
datetick('x', 'HH:MM:SS', 'keepticks');
grid on;
% Adjust the figure for better readability
set(gca, 'FontSize', 12);
Plot Comparison:
I am creating an ESP32 device which will upload data to thingspeak channel and I want the data to be displayed on my website after login. I have succesfully completed the first part of uploading the data to thingspeak. Any suggestions with second part will be very much appreciated.
Helmut
Helmut
Last activity on 20 Aug 2024

Hi,
I tried several times to clear my channel data.
I would expect, when I click on Channel settings-clear channel all data from the channel is gone.
For me the data stay in. Delete channel works fine.
Is there a trick?
many thanks for your help
HEP
I'm almost embarressed enough to not ask this. :) I assumed sorting the "Updated" column in the "My Channels" view would sort my channels based on when data was last written to (last updated to) the channel
However, I have channels that have received date in August and yet the date/time stamp in the Uodated column displays a June date and therefore they sort in the wrong order. Does "update" mean something other than a data update, such as a settings update? If so, if there a way to sort the channels by the more recent data update?
With a deployment of ThingSpeak on August 15th, 2024, we are using a new library for visualization of ThingSpeak channel charts. This should require no changes on your part. If you notice any discrepancies/differences in your channel visualization, please post a screenshot on this thread.
Image Analyst
Image Analyst
Last activity on 12 Aug 2024

Imagine that the earth is a perfect sphere with a radius of 6371000 meters and there is a rope tightly wrapped around the equator. With one line of MATLAB code determine how much the rope will be lifted above the surface if you cut it and insert a 1 meter segment of rope into it (and then expand the whole rope back into a circle again, of course).
Due to API changes at X, formerly known as Twitter, the integration between ThingSpeak and X, specifically the ThingTweet functionality, was not operational for a number of months. As of August 1st, 2024, the ThingTweet functionality is being deprecated.
The alternative, which requires manual steps due to X requiring manual application for a developer account, is to use the TWITTER function from Datafeed toolbox in MATLAB code. You can then create a React that is associated with this MATLAB code to post to X.
I use "x = ThingSpeak.writeFields(myChannelNumber1, myWriteAPIKey1);" in my code to update the ThingSpeak channel. 4 fields are associated with this channel. This statement is executed about once every 5 minutes.
Roughly 60% of the time, I got an error message "HTTP error code -301". The other 40% of time the channel update is successful. What does the "HTTP error code -301" mean? Any suggestion on how to improve the success rate of the channel update
Problem statement: I've written a visualization that I'd like to use on potentially hundreds of different channels in my commerical account. Because it contains code that's unique to the channel (channel id, read API key, etc.) I have to create and maintain a duplicate visualization for each channel. This is wasteful, a source of errors, and almost intractable for a commercial customer with a high channel count.
My request is that MATLAB Visualizations be extended to support parameters, but only a predefined set to reduce the scope. I would propose a subset of the parameters currently supported by the ThingSpeak API. For example, thingSpeakRead supports (requires) readChannelID, NumPoints, and a ReadKey etc. If those were elevated to also be allowed as Visualization parameters, I imagine it would satisfy a large subset of user needs.
The poor man's version of this would be if ThingSpeak supported just one special parameter, such as %CHANNEL_ID%. If this was available within the visualization code one could use it as a key into table to get the other pieces of data like API keys, etc. It would be have to be passed on the visualization url (https://thingspeak.com/apps/matlab_visualizations/573779?readChannelID=xxxxx). Not sure how the visualization would pick it up in the use case where it's called from the ThingSpeak website under the user's list of MATLAB Visualizations. Perhaps it can be prompted for.
I initially considered user defined functions or libraries but they are not supported and I can see that that would require even more development work to support. The workarounds described in this thread aren't suitable for me. https://www.mathworks.com/matlabcentral/answers/2102981-how-to-use-private-functions-lib-in-thingspeak?s_tid=srchtitle_community_thingspeak_14_libraries
thanks!
Tom