Tanusree in MATLAB Answers
최근 활동: 2024년 5월 28일

We collect the real time data from read channel and want process it before sending it to write channel, but the data values in the write channel replicate the read channel values for the following code. Could anyone give suggession how to get the processed data? % Source ThingSpeak Channel ID for reading data readChannelID = 2522808; % Replace with your source channel ID % Destination ThingSpeak Channel ID for writing data writeChannelID = 2522810; % Replace with your destination channel ID % ThingSpeak Read API Key for the source channel readAPIKey = 'XXX'; % Replace with your read API key % ThingSpeak Write API Key for the destination channel writeAPIKey = 'XXX'; % Replace with your write API key %% Read Data %% % Read all available data from the source channel data = thingSpeakRead(readChannelID, 'ReadKey', readAPIKey, 'Fields', [1, 2]); % Extract the values from the read data values1 = data(:, 1); % Values from field 1 i.e. Estimated Voltage values2 = data(:, 2); % Values from field 2 i.e. Input Current % Determine the number of data points retrieved numPoints = size(data, 1); % Assign the number of rows in the variable 'data' to the variable 'numPoints' % Generate timestamps for the data timeStamps = datetime('now') - minutes(numPoints:-1:1); % Initialize Y arrays Y1 = zeros(size(values1)); % Create a new array 'Y1' filled with zeros that has same size as the array 'values1' Y2 = zeros(size(values2)); % Create a new array 'Y2' filled with zeros that has same size as the array 'values2' % Perform the operation Y(i) = i * I(i) for each value in the read data for i = 1:length(values1) disp(['Processing index ', num2str(i)]); disp(['values1(', num2str(i), ') = ', num2str(values1(i))]); disp(['values2(', num2str(i), ') = ', num2str(values2(i))]); Y1(i) = i * values1(i); Y2(i) = i * values2(i); disp(['Y1(', num2str(i), ') = ', num2str(Y1(i))]); disp(['Y2(', num2str(i), ') = ', num2str(Y2(i))]); end % Write the data to the destination channel with timestamps thingSpeakWrite(writeChannelID, 'WriteKey', writeAPIKey, 'Values', [Y1', Y2'], 'Fields', [1, 2], 'Timestamps', timeStamps);
Ritch in MATLAB Answers
최근 활동: 2023년 3월 9일

Hi, I have a few sensors which send data to the thingspeak platform and the data is being displayed correctly. I am trying to analyze this data in MATLAB to detect a pattern and if possible create an alert. Example if someone walks into a room and creates noise or vibrations within a certain frequency it can detect and create an alert. The data I am getting in MATLAB is in the form of a wave therefore setting parameters or being able to extract only data with a certain frequency and display it as an alert would be ideal. How do I approach this? Sorry, very limited programming skills.
보은 이 in Discussions
최근 활동: 2022년 9월 19일

I have a data. And, I want to substract the data using for. But, I want to ignore the nan values and substract others. For example, [1, 2, 3, NaN, 6, 9, 12, 14] ---- substract---> [1, 1, 3, 3, 2] How can I do this? I want to ignore nan values and substract others. What is the expected answer? I'm not clear what you mean by subtract for arrays. [1,2,3,6,9,12,14] - [ 1,1,3,3,2] =? Here is how you can clean the nan values though: A=[1, 2, 3, NaN, 6, 9, 12, 14]; AnoNan=A(~isnan(A)); B = [1, 1, 3, 3, 2]; BnoNan=B(~isnan(B)); Thanks for your answer! I want to this. A=[1, 2, 3, NaN, 6, 9, 12, 14]; ---> B = [A(2)-A(1), A(3)-A(2), A(4)-A(3). A(5)-A(4) ....] But, There is a data including the NaN values in my loop. I want to get the rate of change of sensor data. load('data_20220716.mat'); % SOG[m/s] / COG[rad] / time[sec] data = data2{5, 1}; SOG_time_data = [data(:, 1) data(:, 3)]; COG_time_data = [data(:, 2) data(:, 3)]; threshold_SOG = 0.1; threshold_COG = 0.1; for i = 2 : 1 : length(data) if isnan(SOG_time_data(i-1, 1)) || isnan(SOG_time_data(i-1, 2)) SOG_time_data(i-1, :) = nan; elseif isnan(SOG_time_data(length(data), 1)) || isnan(SOG_time_data(length(data), 2)) SOG_time_data(length(data), :) = nan; end if isnan(COG_time_data(i-1, 1)) || isnan(COG_time_data(i-1, 2)) COG_time_data(i-1, :) = nan; elseif isnan(COG_time_data(length(data), 1)) || isnan(COG_time_data(length(data), 2)) COG_time_data(length(data), :) = nan; end % SOG_time_data_index = [find(isnan(SOG_time_data(:, 1)), 1, 'last'), 1]; % ddd_SOG_time_data(:, :) = SOG_time_data(~isnan(SOG_time_data(i, :))) - SOG_time_data(~isnan(SOG_time_data(i-1, :))); if isnan(SOG_time_data(i-1, 1)) continue else d_SOG_time_data(i-1, :) = SOG_time_data(i, :) - SOG_time_data(i-1, :); end if isnan(COG_time_data(i-1, 1)) continue else d_COG_time_data(i-1, :) = COG_time_data(i, :) -COG_time_data(i-1, :); end end The fucntion diff does that for you. A=[1, 2, 3, NaN, 6, 9, 12, 14]; AnoNan=A(~isnan(A)); AnoNanDiff= diff(AnoNan); Thx Christopher Staples! But, the index of data must not be changed Are you replacing Nan with a value then? If you leave the index constant, you wont be able to do A(4)-A(3) for A=[1, 2, 3, NaN, 6, 9, 12, 14]; nan nan value nan values calculate matlab data processing

ThingSpeak 정보

The community for students, researchers, and engineers looking to use MATLAB, Simulink, and ThingSpeak for Internet of Things applications. You can find the latest ThingSpeak news, tutorials to jump-start your next IoT project, and a forum to engage in a discussion on your latest cloud-based project. You can see answers to problems other users have solved and share how you solved a problem.