使用matlab以数组的形式保存输出?

时间:2016-04-13 14:33:37

标签: arrays matlab matrix

% 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);

t = timer;

t.TasksToExecute = 3;

t.Period = 30;

t.ExecutionMode = 'fixedRate';

t.TimerFcn = @(myTimerObj, thisEvent)disp(query(obj1,'CALCulate:SPECtrum:MARKer0:Y?'));

start(t)

这是我的程序,我必须保存显示的输出值 数组中的Query('CALCulate:SPECtrum:MARKer0:Y?')

1 个答案:

答案 0 :(得分:0)

您需要创建一个变量来保存query(obj1, 'CALCulate:SPECtrum:MARKer0:Y?')的输出。然后,您可以在计时器回调函数中附加到此变量。

%// Initialize a cell array (because I'm not sure of your datatype)
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)

所有其他设置代码都保持不变。