在 matlab 中使用 set 更新图形
我正在尝试使用“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);
但这只是给我带来错误。
I'm trying to update new values to a function using the 'set' function.
Here is the code:
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
The error is that, I don't know how to update multiple variables in a function. for one variable ex:
h=plot(zeros(100,2));
for i=1:20
set(h,'Ydata',rand(10,1));
drawnow;
end
but here I need to update the T,F and P values. How can I use SET to do that?
I tried:
set(plot_handle,'YData',T,F,P);
but thats just giving me errors.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
set
采用名称-值对,即在第一个变量(图形或某些轴的句柄)之后,参数需要替换变量名称
,然后分配给该变量的值
。在失败的示例中,您有三个连续值(
T
、F
和P
),中间没有名称。set
takes name-value pairs, that is, after the first variable (which is a handle to a figure or some axes), the arguments need to alternatename of variable
, thenvalue to assign to that variable
.In your example that failed you have three consecutive values (
T
,F
andP
) without names in between.