Facing problem with the error ''Expected a string scalar or character vector for the parameter name''

조회 수: 18 (최근 30일)
Everytime I want to execute the following programming on ThingSpeak Matlab Analysis, facing problem with thingSpeakWrite, and it is showing ''Expected a string scalar or character vector for the parameter name'' error.
Also how can I write every data instead of single data to write channel on ThingSpeak?
% Read the most recent data from the source channel
data = thingSpeakRead(readChannelID, 'ReadKey', readAPIKey, 'Fields', [1, 2], 'NumPoints', 7);
% Extract the values from the read data
values1 = data(:, 1) % Values from field 1
values2 = data(:, 2) % Values from field 2
% Write the data to the destination channel
thingSpeakWrite(writeChannelID, 'WriteKey', writeAPIKey, [values1, values2], 'Fields', [1, 2]);
  댓글 수: 3
Tanusree
Tanusree 2024년 4월 30일
I changed the programming to discard the NAN values from read channel and only write the remaining datas instead of single data as follows but still it is showing the same error ''Expected a string scalar or character vector for the parameter name'' .
% Find rows containing NaN values and remove them
nanRows = any(isnan(data), 2);
dataWithoutNaN = data(~nanRows, :);
% Loop through each row of data (excluding the first row with NaN values)
for i = 2:size(dataWithoutNaN, 1)
% Extract values from the current row
rowValues = dataWithoutNaN(i, :);
% Convert rowValues to cell array for compatibility with thingSpeakWrite
rowData = num2cell(rowValues);
% Write the current row to the destination channel
thingSpeakWrite(writeChannelID, 'WriteKey', writeAPIKey, 'Fields', [1, 2], rowData{:});
% Pause for a short interval to avoid exceeding ThingSpeak API rate limits
pause(2); % Adjust the interval as needed
end
Stephen23
Stephen23 2024년 4월 30일
이동: Stephen23 2024년 4월 30일
thingSpeakWrite(writeChannelID, 'WriteKey', writeAPIKey, 'Fields', [1, 2], rowData{:});
% this comma-separated list does not produce valid name-value pairs ^^^^^^^^^^
Making random changes is less efficient than following the documentation:

댓글을 달려면 로그인하십시오.

답변 (0개)

커뮤니티

더 많은 답변 보기:  ThingSpeak 커뮤니티

카테고리

Help CenterFile Exchange에서 ThingSpeak에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by