MHz=10^6;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

MyFSC = VISA_Instrument('TCPIP0::172.16.10.10::inst0::INSTR'); %スペアナと接続
idnResponse = MyFSC.QueryString('*IDN?');
fprintf('\nInstrument Identification string: %s\n', idnResponse);
MyFSC.Write('INIT:CONT ON'); %連続掃引

center=str2double(MyFSC.QueryString('FREQ:CENT?'))/MHz; %中心周波数[MHz]
span=str2double(MyFSC.QueryString('FREQ:SPAN?'))/MHz; %スパン[MHz]

RBW=str2double(MyFSC.QueryString('BAND?'))/MHz; %RBW[MHz]
VBW=str2double(MyFSC.QueryString('BAND:VID?'))/MHz; %VBW[MHz]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

MyFSC.Write('INIT:CONT OFF'); %連続掃引停止

MyFSC.Write('INIT'); % スペアナの周波数掃引
MyFSC.QueryString('*OPC?'); %周波数掃引が終わるまで待つ
traceBIN = MyFSC.QueryBinaryFloatData('FORM REAL,32;:TRAC? TRACE1'); %数値データを取得

freq=center-span/2:span/(length(traceBIN)-1):center+span/2;%[MHz]
titlestr=strcat(datestr(t),', RBW=',num2str(RBW),'[MHz], VBW=',num2str(VBW),'[MHz]');

plot(freq,traceBIN,'k.-');
xlabel('MHz')
ylabel('dBm')
title(titlestr);

MyFSC.Write('INIT:CONT ON'); % 連続掃引開始

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

MyFSC.Close()  %スペアナと接続解除