我正在尝试使用'set'函数将新值更新为函数。
以下是代码:
daq_object = analoginput('winsound');
chan = addchannel(daq_object,1);
x=[10];
num_samples = 1000;
axes(handles.axes1);
plot_handle=surf(T,F,10*log10(P),'edgecolor','none');
axis tight;
view(0,90);
xlabel('Time (Seconds)'); ylabel('Hz');
set(daq_object,'SamplesPerTrigger',inf,'SamplesAcquiredFcnCount',num_samples,...
'SamplesAcquiredFcn',{@update_plot,handles});
function update_plot(handles)
data = getdata(daq_object,num_samples);
[S,F,T,P] = spectrogram(data,256,250,256,1E3);
set(plot_handle,'YData',T,F,P); % ERROR WITH THIS, UPDATING THE VARIABLES.
end
错误是,我不知道如何更新函数中的多个变量。对于一个变量ex:
h=plot(zeros(100,2));
for i=1:20
set(h,'Ydata',rand(10,1));
drawnow;
end
但是我需要更新T,F和P值。我如何使用SET来做到这一点?
我试过了:
set(plot_handle,'YData',T,F,P);
但那只是给我错误。
答案 0 :(得分:1)
set
采用名称 - 值对,即在第一个变量(图形或某些轴的句柄)之后,参数需要交替name of variable
,然后{{1} }。
在您失败的示例中,您有三个连续的值(value to assign to that variable
,T
和F
),两者之间没有名称。