Unable to download from dropbox to ThingSpeak using Matlab code.

5 ビュー (過去 30 日間)
Massimobread 2022 年 6 月 9 日
編集済み: Christopher Stapels 2022 年 6 月 9 日
I used the 'Download files from your DropBox API folder using MATLAB' code in thingspeak's matlab analysis, to get a training model.mat file from dropbox, but it just keeps showing not enough input arguments. how do I solve this please? I checked and it went wrong during "narginchk(2,3)" but I just am not sure how and what to do
function downloadFromDropbox(dropboxAccessToken,fileNames,varargin)
dropboxAccessToken='xxx'; %xxx to hide the actual token
% Check to input arguments
% If no file specified, pop up the dialog for the user to select one
if isequal(nargin,2)
%Set default downloadPath to workspace location
downloadPath = pwd;
elseif isequal(nargin,3)
% If downloadPath is provided, check if the given path exists
if ~exist(varargin{1},'dir')
throw(MException('downloadFromDropbox:pathNotFound','Download path does not exist.'));
downloadPath = varargin{1};

回答 (1 件)

Christopher Stapels
Christopher Stapels 2022 年 6 月 9 日
編集済み: Christopher Stapels 2022 年 6 月 9 日
I think you are calling the function with no input arguments.
You have at least two options. You can call the functionin your script, or remove all the mechanics at the top of the function and just make the function part of the script.
For the first option, move this whole function to the end of the script
function downloadFromDropbox(dropboxAccessToken,fileNames,varargin)
and then call the function earlier in the script, making sure to provide all the required inputs
downloadFromDropbox(token, names, localPath);
function downloadFromDropbox(dropboxAccessToken,fileNames,varargin)
This doent make the output available tfor you to use in the session, however, it just saves it to a local space. In ThingSpeak, you dont have access to a local space.
Here is the code I use. Note the trick at the end to convert it to the right file type - you may not need that depending on what your are reading in. You will have to change the name 'myModel.mat' to your filename. IT would probably be best to write it as a variable at teh top od the script.
FName = theFile;
% Generate the custom header
headerFields = {'Authorization', ['Bearer ', dropboxAccessToken]};
headerFields{2,1} = 'Dropbox-API-Arg';
headerFields{2,2} = sprintf('{"path": "/%s"}',FName);
headerFields{3,1} = 'Content-Type';
headerFields{3,2} = 'application/octet-stream';
headerFields = string(headerFields);
% Set the options for WEBREAD
opt = weboptions;
opt.MediaType = 'application/octet-stream';
opt.CharacterEncoding = 'ISO-8859-1';
opt.RequestMethod = 'post';
opt.HeaderFields = headerFields;
% download
tempOutput = webread('https://content.dropboxapi.com/2/files/download', opt);
catch someException
throw(addCause(MException('downloadFromDropbox:unableToDownloadFile','Unable to download file.'),someException));
f = fopen('myModel.mat','w');
ld = load('myModel.mat');


その他の回答  ThingSpeak コミュニティ

Community Treasure Hunt

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

Start Hunting!

Translated by