停止主函数返回值
halt the main function from returning a value
考虑以下示例
function [B] = testtag
f = figure(1)
B = 1;
store_x = []
btn1 = uicontrol(f,'Style', 'pushbutton', 'String', 'tagpoints',...
'Position', [5 5 60 20],...
'Callback', @tagdata);
btn2 = uicontrol(f,'Style', 'pushbutton', 'String', 'storeandreturn',...
'Position', [70 5 80 20],...
'Callback', @returnvalue);
y_axis = [randi([0,20],1,100) randi([20,40],1,100) randi([0,20],1,100)];
x_axis = 1:300;
ax = subplot(1,1,1)
hplot = plot(x_axis,y_axis);
n = 1;
function tagdata(source,callbackdata)
[x, ~] = ginput(2); %saving indexs of the x axis or the time stamp of the place clicked
tic;
store_x(n:n + 1) = x(1:2);
n = n +2;
zoom on
end
function returnvalue(source,callbackdata)
B = store_x
close(figure(1))
end
end
它绘制了一些随机数据并在图的末尾添加了两个按钮,当按下一个按钮时它标记两个数据点成对并将它们存储在矩阵中,之后用户可以放大并标记一些更多的对点,第二个按钮将所有数据点存储到主 return 变量并关闭图形,现在这是我的问题,该函数显然会在输出中 return '1' 因为主函数甚至在调用回调之前就结束了,但我想要的是函数停止,直到所有数据点都存储在 return 变量中,并且当按下第二个按钮时图形关闭,当然没有使用 while 循环),有什么办法吗?
您想使用 uiwait
停止主要功能 returning。
添加
uiwait(f)
在您的主要功能结束时 -> 将等到图形关闭(或发出 uiresume(f)
)继续,因此 return 您的数据。
考虑以下示例
function [B] = testtag
f = figure(1)
B = 1;
store_x = []
btn1 = uicontrol(f,'Style', 'pushbutton', 'String', 'tagpoints',...
'Position', [5 5 60 20],...
'Callback', @tagdata);
btn2 = uicontrol(f,'Style', 'pushbutton', 'String', 'storeandreturn',...
'Position', [70 5 80 20],...
'Callback', @returnvalue);
y_axis = [randi([0,20],1,100) randi([20,40],1,100) randi([0,20],1,100)];
x_axis = 1:300;
ax = subplot(1,1,1)
hplot = plot(x_axis,y_axis);
n = 1;
function tagdata(source,callbackdata)
[x, ~] = ginput(2); %saving indexs of the x axis or the time stamp of the place clicked
tic;
store_x(n:n + 1) = x(1:2);
n = n +2;
zoom on
end
function returnvalue(source,callbackdata)
B = store_x
close(figure(1))
end
end
它绘制了一些随机数据并在图的末尾添加了两个按钮,当按下一个按钮时它标记两个数据点成对并将它们存储在矩阵中,之后用户可以放大并标记一些更多的对点,第二个按钮将所有数据点存储到主 return 变量并关闭图形,现在这是我的问题,该函数显然会在输出中 return '1' 因为主函数甚至在调用回调之前就结束了,但我想要的是函数停止,直到所有数据点都存储在 return 变量中,并且当按下第二个按钮时图形关闭,当然没有使用 while 循环),有什么办法吗?
您想使用 uiwait
停止主要功能 returning。
添加
uiwait(f)
在您的主要功能结束时 -> 将等到图形关闭(或发出 uiresume(f)
)继续,因此 return 您的数据。