Arrays 使用matlab以数组形式保存输出?
这是我的程序,我必须保存显示的输出值Arrays 使用matlab以数组形式保存输出?,arrays,matlab,matrix,Arrays,Matlab,Matrix,这是我的程序,我必须保存显示的输出值 Query('CALCulate:SPECtrum:MARKer0:Y?')在数组中。您需要创建一个变量来保存Query(obj1,'CALCulate:SPECtrum:MARKer0:Y?')的输出。。然后,可以从计时器回调函数中附加到此变量 % Find a VISA-GPIB object. obj1 = instrfind('Type', 'visa-gpib', 'RsrcName', 'GPIB8::1::INSTR', 'Tag', '');
Query('CALCulate:SPECtrum:MARKer0:Y?')
在数组中。您需要创建一个变量来保存Query(obj1,'CALCulate:SPECtrum:MARKer0:Y?')的输出。
。然后,可以从计时器回调函数中附加到此变量
% 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)
所有其他设置代码将保持不变。当我使用该查询时,我的输出值将以浮点形式出现@赛山德尤特甘达姆你期望什么?这段代码没有对任何类型强制转换任何内容(因为我使用了一个单元格数组)。主席先生,它在函数中显示了错误,表示“用法可能是无效的matlab语法”!!单元格数组处理每种数据类型吗?“varargin”表示什么?@SaiSandyuthGandham您必须将上述代码放入函数块中才能执行,因为我在其中有一个子函数
varargin
表示可变数量的输入。
%// 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)