2016-04-13 19 views
0
% 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?')を配列に入れてください。matlabを使用して配列の形で出力を保存しますか?

答えて

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) 

他の設定コードはすべて同じです。

+0

このクエリを使用すると、出力値はfloat形式になります!! – SSG

+0

@SaiSandyuthGandham何を期待していますか?このコードは、(セル配列を使用しているため)何も型にキャストしません。 – Suever

+0

sir、 "使用法が無効なmatlab構文かもしれない"という関数でエラーを表示しています!! – SSG

関連する問題