Can Someone help me with Parse error at function in my matlab code ?
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Sai Gandham
am 19 Apr. 2016
Kommentiert: Gabrielle Gutierrez
am 12 Mai 2018
% Find a VISA-GPIB object.
obj1 = instrfind('Type', 'visa-gpib', 'RsrcName', 'GPIB8::1::INSTR', 'Tag', '');
% Create the VISA-GPIB object if it does not exist
% otherwise use the object that was found.
if isempty(obj1)
obj1 = visa('TEK', 'GPIB8::1::INSTR');
else
fclose(obj1);
obj1 = obj1(1);
end
% Connect to instrument object, obj1.
fopen(obj1);
%// Initialize a cell array
results = {};
%// Define a function to be called when the timer fires
function timerCallback(varargin)
newresult = query(obj1,'CALCulate:SPECtrum:MARKer0:Y?');
%// Display the result (like you currently are)
disp(newresult)
%// Append the result to your results container
results{end+1} = newresult;
end
%// Then set your timer callback
t = timer('TasksToExecute', 3, ...
'Period', 30, ...
'ExecutionMode', 'FixedRate', ...
'TimerFcn', @timerCallback);
start(t)
The above is my code.
I was getting error at line function timerCallback saying that " Parse error at FUNCTION:Usage might be invalid matlab syntax ".
Can someone tell me how to fix this error?
And also I was getting warning at line results{end+1}=newresult; Saying that " The value assigned to variable results might be unused.
If possible let me know how to rectify it.
Expecting answers as early as possible. Thank you in advance !!

0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 19 Apr. 2016
You cannot define a function inside a script. functions can only be defined inside files whose first non-comment is "function" or "classdef".
You need to rename your existing timerCallback.m file to something else such as timer_driver.m . Then once that is done, you need to take the part of it that starts from "function" and save it to the file timerCallback.m . Then you would run the timer_driver code.
2 Kommentare
Gabrielle Gutierrez
am 12 Mai 2018
Functions can be defined within scripts. See the documentation for declaring functions: https://www.mathworks.com/help/matlab/ref/function.html?searchHighlight=function&s_tid=doc_srchtitle
Weitere Antworten (0)
Siehe auch
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
