Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

Need help to find the error in the code below

Asked by Vijith Natarajan on 30 Nov 2012

Hi i tried to acquire the waveform from the agilent scope to matlab using tmtool of instrument control toolbox. when i execute the read waveform function it is showing me an error "undefined function or variable waveformArray".

_Please find the code for Readwaveform function which is already done in tmtool _

function [WaveformArray, ActualPoints, InitialX, XIncrement] = readwaveform(obj, Channel, WaveformSize, MaxTimeMilliseconds, WaveformArray)

libname = get(get(obj, 'Parent'), 'DriverName');

session = get(get(obj, 'Parent'), 'Interface');

Channel = [double(Channel) 0];

WaveformArray = libpointer('doublePtr', WaveformArray);

ActualPoints = libpointer('int32Ptr', 0);

InitialX = libpointer('doublePtr', 0);

XIncrement = libpointer('doublePtr', 0);

status = calllib(libname, 'AgInfiniiVision_ReadWaveform', session, Channel, WaveformSize, MaxTimeMilliseconds, WaveformArray, ActualPoints, InitialX, XIncrement);

WaveformArray = double(WaveformArray.Value);

ActualPoints = double(ActualPoints.Value);

InitialX = double(InitialX.Value);

XIncrement = double(XIncrement.Value);

if (status < 0) errorMessage = libpointer('int8Ptr', repmat(10, 1, 512));

status = calllib(libname, 'AgInfiniiVision_error_message', session, status, errorMessage);

if (status < 0)

error('Failed to interpret error message');


errorMessage = strtrim(char(errorMessage.Value));

error('The instrument returned an error while executing the function.\n%s', errorMessage)


the code i tried to access the read wave form function is below

% Create a device object.

deviceObj = icdevice('AgInfiniiVision.mdd', 'USB0::2391::6038::my51135042::0::INSTR');

% Connect device object to hardware.


% Execute device object function(s).

groupObj = get(deviceObj, 'Waveformacquisition'); groupObj = groupObj(1); [WAVEFORMARRAY] = invoke(groupObj, 'readwaveform', 'channel1');

Please tell me the error in the code


Vijith Natarajan on 30 Nov 2012


an error showing " undefined Variable or function WaveformArray"

Vijith Natarajan on 12 Dec 2012

can anyone pls help on the above question?


No products are associated with this question.

1 Answer

Answer by Image Analyst

Image Analyst (view profile)

on 30 Nov 2012

readwaveform() requires more input arguments than just 'channel1' which you are passing it. Why didn't you pass the other input arguments?


Vijith Natarajan on 30 Nov 2012

Actually when i see webinars regarding this, i saw that we can give the channel information alone rest of things can be ignored.So i tried the same. Is it mandatory to pass all the values?. But why it is showing " undefined Variable or function WaveformArray"

Walter Roberson

Walter Roberson (view profile)

on 12 Dec 2012

Yes, it is mandatory to pass all of the values.

Ankit Desai

Ankit Desai (view profile)

on 12 Feb 2013

You might be confusing a webinar on using IVI-COM drivers with IVI-C drivers. You are using an MDD file based on IVI-C driver. As seen in the code generated by makemid or midedit, and as pointed out by Walter, the function readWaveform takes in 5 arguments (obj, Channel, WaveformSize, MaxTimeMilliseconds and WaveformArray). These input parameters are used by the code in that function.

Not passing any input will cause the code to error out complaining about missing parameter. In your case, you did not pass all the arguments and so when the code reached line 4:

 WaveformArray = libpointer('doublePtr', WaveformArray)

It errored out since it did not find the variable WaveformArray in the input argument.

Here's how the call to that function should look like:

 % Record length.
 recordLength = 1000; %Can be whatever length you want.
 % Pre-allocate buffer to store the data read from scope.
 waveformArray = zeros(1, recordLength);
 % Set the time to wait before the function times out.
 maxTimeOut = 1000;
 waveformArray = invoke(groupObj,'readwaveform','channel1',recordLength, maxTimeOut, waveformArray);

Note:- When you call invoke on groupObj, the first argument that is required by all the driver methods "obj" is taken care of. That is the reason why we are providing only the remaining four arguments (Channel,WaveformSize,MaxTimeMilliSeconds and WaveformArray).

Hope this clears all your doubts.

All the best!

Image Analyst

Image Analyst (view profile)

Contact us