我目前正在尝试显示我在Matlab应用程序设计器应用程序中通过串口接收的数据.我正在遭受线性仪表的极差刷新率(~1 Hz).
仪表的值由固定速率定时器更新,定时器设置为30Hz.计时器回调中的时间戳打印显示我以正确的频率调用它.我的计算机非常强大,任务管理器没有显示任何高负载的迹象 - 实际上,MATLAB应用程序几乎不消耗任何CPU时间.它实际上不仅仅是仪表而是所有UI元素.
所以我的猜测 - 或更好:我的希望 - 是刷新率必须有一些硬性上限.但是,官方文档没有提供有关如何更改此内容的任何提示.
我的MATLAB版本是R2016b.
所以我的问题:
这是用R2017a修复的吗?
如果没有:我可以做些什么,即摆弄MATLAB内置文件?
这是一个MCV示例,演示了这个问题:
classdef testapp < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
andwatchhowthisstartstospinsmoothlyGaugeLabel matlab.ui.control.Label
andwatchhowthisstartstospinsmoothlyGauge matlab.ui.control.SemicircularGauge
KeepturninghereKnobLabel matlab.ui.control.Label
KeepturninghereKnob matlab.ui.control.Knob
end
properties (Access = private)
tim_the_timer
i = 0;
end
methods (Access = private)
function app = refreshMeter(app, ~,~)
% display timestamp
datestr(now,'HH:MM:SS.FFF')
% update the gauge
app.andwatchhowthisstartstospinsmoothlyGauge.Value = app.i;
app.i = app.i + 1;
if app.i > 100
app.i …Run Code Online (Sandbox Code Playgroud) matlab user-interface refresh data-visualization matlab-app-designer
MATLAB 提供了该addlistener函数。
侦听器允许我们跟踪对象属性的变化并对其采取行动。例如,我们可以创建一个非常简单的侦听器,当对象的'YLim'属性axes发生更改时,它将在命令窗口中显示一条消息:
% Example using axes
ax = axes();
addlistener(ax, 'YLim', 'PostSet', @(src, evnt)disp('YLim changed'));
Run Code Online (Sandbox Code Playgroud)
尝试平移轴或放大/缩小,看看会发生什么。这工作正常。
我需要做同样的事情,但使用 anuiaxes代替。
不幸的是,我们似乎不允许这样做。尝试运行以下示例:
% Example using uiaxes
ax = uiaxes();
addlistener(ax, 'YLim', 'PostSet', @(src, evnt)disp('YLim changed'));
Run Code Online (Sandbox Code Playgroud)
它抛出这个错误:
错误使用 matlab.ui.control.UIAxes/addlistener 添加 PostSet 侦听器时,类“matlab.ui.control.UIAxes”中的属性“YLim”未定义为 SetObservable。
我已经阅读了“监听属性值的变化”和“观察属性值的变化”的文章,我了解到必须声明一个属性才能SetObservable被监听:
classdef PropLis < handle
properties (SetObservable)
ObservedProp = 1 % <-- Observable Property
end
end
Run Code Online (Sandbox Code Playgroud)
我试过通过查看UIAxes类定义,edit matlab.ui.control.UIAxes但这是不可能的,因为它是一个P-file。 …
matlab listener observable matlab-figure matlab-app-designer
最近在UndocumentedMatlab上发表的一篇文章提到App Designer图实际上是使用Dojo Toolkit的网页.这意味着我们理论上可以直接操作HTML DOM来实现某些不可用的UI自定义.
下面是App Designer图形定义的示例,如.mApp Designer生成的文件中所示(在MATLAB R2016a上):
classdef domDemo < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure % UI Figure
LabelListBox matlab.ui.control.Label % List Box
ListBox matlab.ui.control.ListBox % Item 1, Item 2, Item 3, It...
end
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
end
end
% App initialization and construction
methods (Access = private) …Run Code Online (Sandbox Code Playgroud) matlab dojo customization undocumented-behavior matlab-app-designer
我在Matlab App Designer应用程序中有不同的回调。就我而言,有几个按钮。我需要为此使用相同的变量。
使用在另一个回调中创建的变量时,我只会收到错误消息。
基于这个问题Calculate Y axis of an image from graph point of origin我尝试在应用程序设计器GUI中执行相同的操作,但它不起作用。我附加了一张图像,显示该图像不是从图形原点开始的,并且由于set命令,我得到了一个新图形。知道如何修复/做吗?
代码:
function ButtonPushed(app, event)
url='https://icons.iconarchive.com/icons/thesquid.ink/free-flat-sample/512/owl-icon.png';
I = imread(url);
I = rgb2gray(I);
I=flipud(I);
imshow(I,'Parent', app.imageAxes);
set(gca,'YDir','normal')
end
Run Code Online (Sandbox Code Playgroud)
我做了一个带有两个按钮和轴的应用程序设计器 GUI。第一个(LoadimageButton)正在加载纸张图像,我可以标记点,直到按转义键。第二个按钮是打印点坐标(PositionButton)。
我注意到按下两个按钮后我可以移动轴上的点并更改它们的位置或删除它们。问题是,当我按下删除键(在上下文菜单中)时,按下 PositionButton 后出现此错误:
Error using images.roi.Point/get
Invalid or deleted object.
Error in tempDrwPnt1/PositionButtonPushed (line 61)
positions = cell2mat(get(app.pointhandles, 'position'))
Error while evaluating Button PrivateButtonPushedFcn.
Run Code Online (Sandbox Code Playgroud)
删除点后如何刷新 app.pointhandles?
代码:
function LoadimageButtonPushed(app, event)
imshow('peppers.png','Parent',app.ImageAxes);
userStopped = false;
app.pointhandles = gobjects();
while ~userStopped
roi = drawpoint(app.ImageAxes);
if ~isvalid(roi) || isempty(roi.Position)
% End the loop
userStopped = true;
else
% store point object handle
app.pointhandles(end+1) = roi;
end
end
addlistener(roi,'MovingROI',@allevents);
addlistener(roi,'ROIMoved',@allevents);
app.pointhandles(1) = [];
function allevents(src,evt)
evname = evt.EventName;
switch(evname)
case{'MovingROI'}
disp(['ROI moving …Run Code Online (Sandbox Code Playgroud) 我在某个文件夹中有一个MATLAB App App.mlapp~/myapp/.它使用的功能和GUI中使用的一些图形都在~/myapp/subfolder.为了正确运行App.mlapp,我必须~/myapp/subfolder在启动应用程序之前每次手动添加到我的路径.
如何自动添加子文件夹?
我试着把它放在addpath(genpath(~/myapp/subfolder));开头StartupFcn.但是,正如StartupFcn在组件创建之后调用的那样,已经需要一些图形~/myapp/subfolder,这种方法不起作用.使用自动创建的功能创建组件createComponents,无法使用App Designer编辑器对其进行编辑.
最小的例子,根据excaza的要求.要创建它,请打开App Designer,创建一个新应用程序,在设计视图中添加一个按钮,并在路径中使用按钮属性 - >文本和图标 - >更多属性 - >图标文件指定一个图标 .然后从路径中删除该图标的目录,并尝试运行该应用程序.
classdef app1 < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
Button matlab.ui.control.Button
end
% App initialization and construction
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure
app.UIFigure = uifigure;
app.UIFigure.Position = [100 …Run Code Online (Sandbox Code Playgroud) 如何使用waitfor或uiwait在MATLAB的应用程序设计师?这些功能仅适用于数字(GUIDE)而非应用程序设计器窗口.如何在应用程序设计器中具有相同的行为?在等待主窗口代码之前我正在等待关闭第二个窗口.
uifigure在将焦点切换为不同的图形后,如何将焦点设置为a ?
因为uicontrol,可以将焦点设置在其子元素之一上.例如:
% create a new uicontrol text label
h = uicontrol('style','text','string','This is my figure');
% create a figure to switch the focus
figure;
% switch back
uicontrol(h)
Run Code Online (Sandbox Code Playgroud)
但是,因为uifigure采用类似的代码只会创建一个新的uifigure.
一些代码供您尝试:
% create a new uifigure
h = uifigure('Name','This is my figure');
% create a new uilabel as a child of uifigure
lh = uilabel(h)
% create a figure to switch the focus
figure;
% this creates a new uifigure then switch back …Run Code Online (Sandbox Code Playgroud) 在matlab appdesigner的uiax中是否有任何变通方法来添加平移和缩放功能?appdesigner是在matlab r2016a中引入的,并且正式不支持这些选项。
我在 appdesigner (Matlab) 中创建了一个非常简单的 GUI,带有一个下拉菜单。此外,我将生成的代码(在“代码视图”选项卡下)粘贴到普通的 .m 文件中(因为我想进一步向此代码添加更多内容)。我的问题是如何从这个自生成的代码中访问某些变量,以便我可以在主类之外使用该值?
例如:
在 App 类中,对于这个下拉菜单部分,生成了以下代码行:
app.ColorDropDown = uidropdown(app.UIFigure);
app.ColorDropDown.Items = {'Red', 'Blue', 'Yellow'};
app.ColorDropDown.Position = [277 178 140 22];
app.ColorDropDown.Value = 'Red';
Run Code Online (Sandbox Code Playgroud)
在此应用程序类之外:根据在此下拉菜单中选择的值,我想在正常变量中捕获该值,并根据所选颜色显示其他一些结果
谢谢