简体   繁体   English

无法在 App Designer MATLAB 下同时运行两个函数

[英]Unable to run two function simultanously under App Designer MATLAB

Objective客观的

The objective is to run two functions simultaneously using app that design using App designer.目标是使用应用程序设计器设计的应用程序同时运行两个功能。 In general, there are 3 main blocks一般来说,有3个主要块

1) App1. 1)应用程序1。 The apps contains 1 state button (eg, STOP BUTTON) and 1 button (TASK).应用程序包含 1 个状态按钮(例如,停止按钮)和 1 个按钮(任务)。

2) Function FirstTask. 2) 函数FirstTask。 Under the hood, datetime is sampled at every iteration.在幕后,每次迭代都会对日期时间进行采样。

3) Function SecondTask. 3) 函数SecondTask。 Similarly, under the hood, datetime is sampled at every iteration.同样,在幕后,每次迭代都会对日期时间进行采样。

** For reproduciabilty, we simplify the example of sampling datatime. ** 为了可重复性,我们简化了采样数据时间的示例。

The procedure are as follow;程序如下;

Function FirstTask is execute at the beginning/startup of App1.函数 FirstTask 在 App1 的开始/启动时执行。

Whereas, Function SecondTask only executed after the Button TASK being pressed.而 Function SecondTask 仅在按下 Button TASK 后执行。

Both Function FirstTask and Function SecondTask terminated simultaneously after STOP BUTTON being pressed.按下停止按钮后,Function FirstTask 和Function SecondTask 同时终止。

Observations观察

There are three observations made;进行了三个观察;

1) Function FirstTask is execute as intended at the beginning/startup of App1. 1) 函数 FirstTask 在 App1 的开始/启动时按预期执行。

2) Function SecondTask is execute as intended after the Button TASK being pressed. 2) 按钮TASK 被按下后,函数SecondTask 按预期执行。

3) The Function FirstTask is put to halt after Button TASK being pressed despite being independent of the Button TASK. 3) 尽管独立于 Button TASK,但在按下 Button TASK 后,Function FirstTask 被暂停。

My question is, how to tackle the observation No 3. Because, we required both Function FirstTask and Function SecondTask to run simultaneously.我的问题是,如何解决观察号 3。因为,我们需要 Function FirstTask 和 Function SecondTask 同时运行。

The code to reproduce the above problem are重现上述问题的代码是

1) Code at the app1. 1) app1 处的代码。

methods (Access = private)
    % Code that executes after component creation
    function startupFcn(app)
        FirstTask(app)
    end
    % Button pushed function: RunSecondTaskButton
    function RunSecondTaskButtonPushed(app, event)
        SecondTask(app)
    end
end

2) Function FirstTask 2) 函数FirstTask

function FirstTask(Gui)
initVar=1;
MaximumData=1000; % Maximum before we append further
FirstData=NaT(MaximumData,1); % Prelocate
while Gui.StopButton.Value==0  % Loop while button stop no click
    FirstData(initVar)=datetime('now','Format','HH:mm:ss.SSS');   % add the time vector duration for each day
    initVar=initVar+1;
    pause(1)
end
end

3) Function SecondTask 3)函数SecondTask

function SecondTask(Gui)
initVar=1;
MaximumData=1000; % Maximum before we append further
SecondData=NaT(MaximumData,1); % Prelocate
while Gui.StopButton.Value==0  % Loop while button stop no click
SecondData(initVar)=datetime('now','Format','HH:mm:ss.SSS');   % add the time vector duration for each day
    initVar=initVar+1;
    pause(1)
end
end

The full code is attach in this thread.完整代码附在此线程中。 Really appreciate for any advice on this matter.非常感谢您对此事的任何建议。

Thanks to the suggestion.感谢建议。 Using timer, the following can realised by something like.使用定时器,下面可以通过类似的东西来实现。

        app.GraphTimer=timer;
        app.GraphTimer.TimerFcn = @app.FirstTaskx;
        app.GraphTimer.ExecutionMode  = 'fixedRate';

In the function,within the app designer在功能中,在应用程序设计器中

    function FirstTaskx(app,~,~)
        FirstTask(app)
    end

Repeat the same for the second task.对第二个任务重复相同的操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 MATLAB应用程序设计器:在两个应用程序之间共享数据(在启动功能中,不使用按钮提取第二个应用程序中的数据) - MATLAB app designer: Share data between two apps (in startup function not using button to extract data in second app) MATLAB App Designer重置属性 - MATLAB App Designer reset properties 使用 parfeval() 时的 Matlab-GUI 警告:“无法保存 App Designer 应用程序 object。” - Matlab-GUI warning when using parfeval(): “Unable to save App Designer app object.” 如何仅允许运行一个在MATLAB的APP DESIGNER中创建的应用实例? - How can I allow only one instance of app to run which created in APP DESIGNER of MATLAB? matlab 应用程序设计器在新应用程序中加载图像 - matlab app designer load image in new app 如何在MATLAB App Designer中使用属性在两个应用程序之间共享数据? - How to use properties to share data between two apps in MATLAB App Designer? 如何使用Matlab APP DESIGNER在用户界面中同时显示两个单独的图像? - How to display two separate images simultaneously in a user interface using the Matlab APP DESIGNER? 使用Matlab App Designer获取鼠标点 - Getting Mouse Points using Matlab App Designer 如何将Picturebox添加到Matlab App Designer? - How to add picturebox to Matlab App Designer? MATLAB App Designer 保持打开/关闭抛出警告 - MATLAB App Designer hold on/off throwing warnings
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM