Highlights
팔로우


Adam Danz
조회 수: 10(최근 30일)

Four New App Features in MATLAB R2021a

Adam Danz 2021년 5월 10일 (2021년 5월 10일에 수정됨)
최근 활동 Life is Wonderful답글 2021년 5월 12일

Four (of many) new features for Apps in MATLAB R2021a

These four new features are the solutions to many inquiries in the Answers forum that continue to receive hundreds of views per month long after they were asked.

Table of Contents

  • Keyboard Shortcuts for UI Components
  • Programmatically scroll UITables
  • Figure always on top
  • UI hyperlink component
  • Demo app: Keyboard shortcut challenge

Keyboard Shortcuts for UI Components

Keyboard shortcuts can now change the focus and make contiguous and non-contiguous selections in ListBox, Table, DatePicker, and ColorPicker menus created in uifigures. The table below summarizes the shortcuts made available in R2021a ( release notes ).

Reminder: in MATLAB R2020b and later you can change the tab order of objects in an app by changing their stack order in AppDesigner using the Reorder tool in the drop-down menu or by right-clicking the component and selecting Reorder from the menu (see R2020b release notes and a screenshot in the Answers forum ).

Programmatically scroll UITables

The scroll function was added in R2016a but as of R2021a it can be used with uitables to programmatically scroll to the top, bottom, left, or right of a table or to a specific row, column or cell ( release notes ). Combined with a uistyle (R2019b) you can scroll to and highlight any part of the uitable.

Syntax examples:

Figure always on top

Figures created with uifigure now have an additional WindowStyle property: 'alwaysontop' ( release notes ). Figures with this setting will stay on top of other windows but unlike the modal option, other windows are still accessible.

See the WindowStyle property description for tips on setting and changing this property.

To toggle the AlwaysOnTop state of your app using a checkbox, state button, or another UI component, follow this callback function template,

function alwaysOnTopCheckBoxValueChanged(app, event)
    value = app.alwaysOnTopCheckBox.Value;
    if value
        app.UIFigure.WindowStyle = 'alwaysontop';
    else
        app.UIFigure.WindowStyle = 'normal';
    end
end

UI hyperlink component

Use the uihyperlink function or the UI hyperlink component in App Designer or a uifigure to add and configure a clickable link ( release notes ). The hyperlink can be assigned to a figure, panel object, tab object, ButtonGroup, or GridLayout object when created in a uifigure. In addition to setting the text and URL, there are lots of properties to control the text format including the VisitedColor property that controls the color of the text after the link is clicked and an optional user-defined HyperlinkClickedFcn function that is evoked when the link is clicked.

Demo app: Keyboard shortcut challenge

The attached zip file contains an app, keyboardShortcutsDemo_R2021a.mlapp , that demonstrates these 4 features. The app displays the extent of arctic sea ice from 1979 to 2016 during the months when extent typically maximizes and minimizes.

Mouseless challenge: After opening the app, without using your mouse, try the following.

  • Select a month (September or March) and any number of years from the list boxes
  • Navigate through the Date Picker and select a date within the range or your selected years (disabled when only 1 year is selected).
  • Navigate to the always-on-top checkbox to pin the app to the top of other windows.
  • Navigate to the text box and enter a year that appears in the uitable to go to that row in the uitable (disabled when only 1 year is selected).
  • Navigate to the URL and press Enter to open the website containing the raw data.

Download the attached zip file, FourNewAppFeatures_R2021a.zip, for a Live script copy of this thread and an app that demonstrates each feature.

Life is Wonderful
Life is Wonderful 2021년 5월 12일

Hi Adam, Thanks a lot for the explanation, since i was writing the app code which needs your new changes, unfortunately I have to miss out. I was introducing the similar search for word from loaded text data , please suggest alternate way. Thanks you so much for all the help.

Life is Wonderful
Life is Wonderful 2021년 5월 11일 (2021년 5월 11일에 수정됨)

Hi Adam, Thanks for sharing the app. I see features are lost across R2020b and R2021a version. Adapting across version may be a help with the attached difference.

Adam Danz
Adam Danz 2021년 5월 11일 (2021년 5월 11일에 수정됨)

Hi Jogger, thanks for your comment and interest in the app!

Since the app is intended to demonstrate new features available in Matlab R2021a, it uses features that were not available prior to the current release. Otherwise, I would agree that backward compatibility with recent releases is important.

Notice that the sections you highlighted are all grayed-out and un-editable in the app in Code View. Those sections are auto-generated by Matlab according to the version of Matlab being used. So, even if I needed to modify those sections, I could not do so.

If I had to modify the app so that it was functional in R2021a+ and releases prior to R2021a, I would need to change 3 objects:

  1. the "go to year" text box would not function since the scroll function is not supported with uitables prior to 21a.
  2. The "always on top" checkbox would not function since this WindowStyle only became available in 21a.
  3. The hyperlink would also not work prior to 21a.

But since I cannot edit the sections of the app that construct these objects, I would have to remove the objects from DesignView and create them programmatically within the Start function of the app.

Then, I would add a condition using verLessThan('Matlab','9.10') to detect if the Matlab version is < R2021a in which case I could either

  • not create those objects
  • create them with limited features, or
  • create them but disable them so the user knows they are there but function-less. Maybe even throw in a tooltip to explain why they are disabled.

Some alternatives to these features prior to R2021a:

  • Hyperlink alternative: You can assign a ButtonDownFcn to a text object. Here's an example of that in a uifigure .
  • Always on top alternative: You can set the WindowSyle to modal but that comes with some additional baggage: you won't be able to interact with any of the other Matlab windows.
  • UITable Scroll: An alternative is to use some Java magic demonstrated in several answers in the forum ( ans1 , ans2 ) but this is not functional with uitables in uifigures (at least it wasn't when I tested it a couple years ago).

Lastly, some of the changes highlighted in your code comparison are just line number changes. For example the app.UIAxes.___ lines starting on line 200 of the R2021a version is merely moved to line 313+ in your R2020b code.

Thanks for sharing the code comparison images!