主要内容

搜索


With MATLAB Online, your students do not need a high-end computer to install and use MATLAB. Instead, they just need a web-connected computer. MATLAB Online lets students connect their webcam to capture live videos and images. Here’s an example of performing a simple object detection using a pretrained neural network called AlexNet and a live feed from a webcam. Google Chrome™ is required for webcam support.

Read more about it in the documentation, or take a look at this video for additional examples.

Are you looking for ideas to provide students a more effective learning experience in an online or hybrid environment? A collection of videos on Online Teaching with MATLAB and Simulink demonstrates resources for providing hands-on experience with MATLAB and Simulink, plus examples of delivering instruction, engaging students using virtual labs and projects, and assessing outcomes in your preferred learning platform.

View ‘Online Teaching with MATLAB and Simulink’ video series

Several educators worldwide use MATLAB Grader to scale assessments and automatically grade MATLAB coding assignments. MATLAB Grader can be used in any learning environment, for both formative assessments with automated feedback and summative assessments, such as quizzes and exams.

To get you started easily, you can access MATLAB Grader problem collections that include domains like Calculus, Programming, Dynamics, and more. Adapt these examples to your curriculum or use them as is to generate quick exercises for your students and reinforce MATLAB skills. The examples illustrate some best practices for how to design assessments, test for common errors, and write rich feedback for students to help them iterate and improve on their solutions.

Request access to the problem collections through Customer Support or your assigned Customer Success Engineer or Account Representative. They ensure that only authorized instructors gain access to the problem collections.

If you are new to MATLAB Grader, watch the MATLAB Grader Overview video and try the interactive Teaching with MATLAB online course (Section 6 is about MATLAB Grader).

Check out the following webinar by Prof. Rick Hill to learn how you can use the new interactive Live Script Control Tutorials for MATLAB and Simulink for your teaching! Examples demonstrate interactive control design with Bode plots, Nyquist diagrams, engaging animations, and much more.

https://www.youtube.com/watch?v=ZMWYlmqapfc

One of the objectives of lab-based instruction can be to develop students’ familiarity with hardware equipment. When students could no longer come to their lab in person, educators at HTW Dresden developed a MATLAB app using App Designer to replicate the controls on lab equipment such as a signal generator and oscilloscope. Read this article to learn more about how Dr. Henker and Dr. Kelber virtualized their electrical engineering labs.

If you use Simulink or Simscape models for your virtual labs, you can create an interactive display of controls and displays within your model diagram using blocks from the Dashboard library. To do so, connect block parameters to control blocks (knobs, buttons, and switches) and signals to displays blocks (scopes and gauges).

New customizable Knob, Vertical Slider, and Horizontal Slider blocks introduced in R2021a let you choose your own background image, foreground image, handle or slider image, and scale appearance. By combining these with custom gauge blocks, you can create intuitive and photo-realistic dashboards for interacting with your models, such as in the image below.

View examples of controlling simulations with interactive displays, or read some more Tips for Moving your Lab-based Classes Online.

I am trying to simulate the PMSM in fault mode with phase loss at 0.25 sec, but the simulation results are incorrect. For example, the rotor speed changes too much when a phase is missing. I tried to assemble the model in dq coordinates and abc coordinates on my own, but the results are the same. Who can tell you how to modify the engine model so that the simulation shows the correct results?

Starting in MATLAB R2021a axis tick labels will auto-rotate to avoid overlap when the user manually specifies ticks or tick labels ( release notes ). In custom visualization functions, the tick label density or tick label lengths may be variable and unknown. The new auto-rotation feature removes the burden of detecting the need to rotate manually-set labels and eliminates the need to manually rotate them.

Many properties and combinations of properties can cause tick labels to overlap if they are not rotated.

  • Length of tick labels
  • Number of tick labels
  • Interval between tick labels
  • Font size
  • Font name
  • Figure size
  • Axes size
  • Viewing angle of the axes

Demo: varying tick density and length of tick labels

These 9 axes vary by the number of x-ticks and length of x-tick-labels. MATLAB auto-rotates the labels when needed.

Demo: Changes to axis view angle and rotation

The auto-rotation feature updates the label angles as the axes change programmatically or during user interaction.

What if I don't want auto-rotation?

Auto-rotation mode is on by default for each X|Y|Z axis. When the tick label rotation angle is manually set from the X|Y|ZTickLabelRotation property of axes or by using xtickangle | ytickangle | ztickangle , auto-rotation is turned off. Auto-rotation can also be turned off by setting the X|Y|ZTickLabelRotationMode axis property to manual but it's important to also hold the axis properties so that the rotation mode does not revert to the default value, auto. If you're looking for a broader method of reverting to older behavior you can set the default label rotation mode to manual at the start of a function that produces multiple plots and then revert to the factory default rotation mode at the end of the file (consider using onCleanup).

set(groot,'defaultAxesXTickLabelRotationMode','manual')
set(groot,'defaultAxesYTickLabelRotationMode','manual')
set(groot,'defaultAxesZTickLabelRotationMode','manual')
% Revert to factory-default
set(groot,'defaultAxesXTickLabelRotationMode','remove')
set(groot,'defaultAxesYTickLabelRotationMode','remove')
set(groot,'defaultAxesZTickLabelRotationMode','remove')

A copy of this Community Highlight is attached as a live script.

If you teach ordinary differential equations (ODEs) or use ODEs in your class, a common challenge you may have encountered is helping your students overcome the ‘mathematical intimidation’ of the concepts. You can use the Phase Plane and Slope Field apps, developed and shared by the MathWorks Online Teaching team, to let your students develop a visual intuition of ODEs by qualitative analysis.

These apps capture the functionality of the wildly popular PPlane and DField apps created by John C. Polking in MATLAB between 1995 and 2003. While similar in function to the original apps, the Slope Field and Phase Plane apps have been written entirely from scratch in MATLAB App Designer using modern MATLAB coding practices. This makes the new apps easier to maintain, edit, and use.

Get the apps on GitHub, and visit the MATLAB and Simulink Courseware page for more curriculum resources tailored to multiple disciplines.

MATLAB, Simulink, and their support for a variety of low-cost hardware has allowed many students to continue benefit from project-based learning, even from their own homes. Popular choices include the Arduino Engineering Kit and Raspberry Pi.

If you use or are considering using Raspberry Pi for your class, your students could benefit from using the Raspberry Pi Resource Monitor App. This app, introduced in MATLAB R2020b, will allow them to graphically configure target boards, deploy Simulink models and MATLAB functions, manage peripheral devices and interfaces, and perform common troubleshooting steps. Such an approach can simplify many of the technical challenges faced by educators who adopt a ‘Hardware at Home’ approach for their lab-based classes.

Click here to learn more about Raspberry Pi support from MATLAB and Simulink.

You may also want to learn more about Virtual Labs and Projects with MATLAB and Simulink, or read some Tips for Moving your Lab-based Classes Online.

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.

MATLAB EXPO 2021 was held earlier this week. This global online event featured presentations and hands-on workshops covering topics from AI, to Application Deployment, and from Algorithm Development, to Teaching with MATLAB and Simulink. Dr. Magnus Egerstedt, Steve W. Chaddick School Chair and Professor of Electrical and Computer Engineering at Georgia Institute of Technology, spoke about Robotarium - a remotely accessible swarm robotics lab that remains freely accessible to anyone.

Robotarium allows users from all over the world to upload control code written in MATLAB and run experiments. Creating a swarm robotics lab is resource intensive, so such a remote access solution can be a great alternative. Watch Prof. Egerstedt introduce Robotarium.

You may also want to learn more about Virtual Labs and Projects with MATLAB and Simulink, or read some Tips for Moving your Lab-based Classes Online. If you are in China, Japan, or Korea, click here to register for dedicated EXPO events this summer.

Climate Data Toolbox was developed by Chad Greene, a postdoctoral research fellow at NASA Jet Propulsion Laboratory, and Kelly Kearney, a research scientist at University of Washington. The Climate Data Toolbox is freely downloadable from File Exchange and has been downloaded over 5,000 times since 2019.

The toolbox was inspired by one big idea: There are a common set of tasks related to data processing, analysis and visualization that Geoscience researchers and students working with climate data typically perform. Greene and coauthors make the case in their paper published in Geochemistry, Geophysics, Geosystems that having everyone who is tackling climate analysis separately recoding these same tasks is not a good use of time, for the individual or the collective, as it takes away from other more innovative climate work. Better to have a set of reusable, publicly shared functions for those repetitive tasks.

Recently, Lisa Kempler published an example of how to look at the change in temperature of the Pacific Ocean over time using MATLAB and the Climate Data Toolbox.

Try the example here by loading up MATLAB, installing the Climate Data Toolbox, and following along the tutorial.

Educators make their course material more interactive, promote self-directed learning, and increase student engagement through Live Editor. One of the advantages it offers is animated figures in your Live scripts. This can help students better understand dynamic systems such as the motion of a projectile or a double pendulum through visualization. With R2021a, you can now replay animations and explore individual frames without having to re-run the code.

To do so, use the playback controls that appear within the figure window after an animation is done playing. You can view and run this example animation within your browser.

Learn more about creating and sharing live scripts for applications such as flipped classrooms on this Instructional Resources page.

MATLAB EXPO 2021 is May 4-5, 2021!

MATLAB EXPO is open to everyone:

  • It's free.
  • It's online.
  • Register now. [Edit: Registration is closed]

Industry Tracks:

  • AI in Engineering
  • Modeling and Simulation
  • Implementation, Verification, and DevOps
  • Algorithm Development and Deployment
  • 5G and Radar
  • FPGA, ASIC, and SoC Design
  • Autonomous Systems
  • Teaching with MATLAB and Simulink
  • Cloud and IoT
  • Motor and Power Control

Special Event: Women in Tech Ignite Session

Women in Tech Ignite is a networking event where the MATLAB community can meet and be inspired by a diverse group of women engineers and scientists and hear about the innovative ways they use MathWorks products. Attendees of all genders are welcome.

[Edit: Registration is closed]

We introduced Difficulty Rating functionality during 2020 Cody Contest. Our Cody players have provided difficulty rating for most of the problems. Now we are displaying the ratings in the Problems list view.

Sorting and Filtering to follow...

Many educators use Simulink for their virtual labs. Starting in R2021a, you can add comments to blocks in a Simulink model. If you use Simulink in your class, you can use this to prompt questions to your students or to provide them feedback. Students working in groups can collaborate directly in the Simulink Editor, such as by suggesting alternative designs.

Click here to learn how to view, add, and reply to comments on blocks.

You may also want to learn more about Virtual Labs and Projects with MATLAB and Simulink, or read some Tips for Moving your Lab-based Classes Online.

Introducing content recommendations, a new feed on the community home page with personalized content just for you. MATLAB Central has hundreds of thousands of posts, including files, blogs, questions, and answers. We’re always looking for opportunities to better serve the community as it continues to grow so that visitors can easily help one another and ultimately find what they're looking for.

MATLAB Central has been around for a long time, 20 years this year - more on this milestone in a separate post later. With so much great content it can be a challenge to find what you're looking for or discover new things. We have search and browsing capabilities across the community but even with these robust features you still might not discover some very interesting or relevant content. In the spirit of trying to make sure you don't miss out, we've just released our first version of our recommended content feed. You can see this new feed on the community home page, visible by default via the 'For You' tab.

Recommendations are pulled from across MATLAB Central based on what we think would be relevant to you. We think we have a good starting point and plan on tweaking the algorithms now that it's live. So, expect the feed to only get more relevant over time.

We hope you will find this feature helpful and as always please reply with any feedback you may have.

New in R2021a, LimitsChangedFcn

LimitsChangedFcn is a callback function that responds to changes to axis limits ( release notes ). The function responds to axis interaction such as panning and zooming, programmatically setting the axis limits, or when axis limits are automatically adjusted by other processes.

LimitsChangedFcn is a property of ruler objects which are properties of axes and can be independently set for each axis. For example,

ax = gca(); 
ax.XAxis.LimitsChangedFcn = ... % Responds to changes to XLim
ax.YAxis.LimitsChangedFcn = ... % Responds to changes to YLim
ax.ZAxis.LimitsChangedFcn = ... % Responds to changes to ZLim

Previously, a listener could be assigned to respond to changes to axis limits. Here are some examples.

However, LimitsChangedFcn responds more reliably than a listener that responds to setting/getting axis limits. For example, after zooming or panning the axes in the demo below, the listener does not respond to the Restore View button in the axis toolbar but LimitsChangedFcn does! After restoring the view, try zooming out which does not result in changes to axis limits yet the listener will respond but the LimitsChangedFcn will not. Adding objects to axes after an axis-limit listener is set will not trigger the listener even if the added object expands the axis limits ( why not? ) but LimitsChangedFcn will!

ax = gca(); 
ax.UserData.Listener = addlistener(ax,'XLim','PostSet',@(~,~)disp('Listener')); 
ax.XAxis.LimitsChangedFcn = @(~,~)disp('LimitsChangedFcn')

How to use LimitsChangedFcn

The LimitsChangedFcn works like any other callback. For review,

The first input to the LimitsChangedFcn callback function is the handle to the axis ruler object that was changed.

The second input is a structure that contains the old and new limits. For example,

    LimitsChanged with properties:
      OldLimits: [0 1]
      NewLimits: [0.25 0.75]
         Source: [1×1 NumericRuler]
      EventName: 'LimitsChanged'

Importantly, since LimitsChangedFcn is a property of the axis rulers rather than the axis object, changes to the axes may clear the LimitsChangedFcn property if the axes aren't held using hold on. For example,

% Axes not held
ax = gca(); 
ax.XAxis.LimitsChangedFcn = @(ruler,~)title(ancestor(ruler,'axes'),'LimitsChangedFcn fired!'); 
plot(ax, 1:5, rand(1,5), 'o')
ax.XAxis.LimitsChangedFcn
ans =
    0×0 empty char array
% Axes held
ax = gca(); 
hold(ax,'on')
ax.XAxis.LimitsChangedFcn = @(ruler,~)title(ancestor(ruler,'axes'),'LimitsChangedFcn fired!'); 
plot(ax, 1:5, rand(1,5), 'o')
ax.XAxis.LimitsChangedFcn
ans =
  function_handle with value:
    @(ruler,~)title(ancestor(ruler,'axes'),'LimitsChangedFcn fired!')

Demo

In this simple app a LimitsChangedFcn callback function is assigned to the x and y axes. The function does two things:

  1. Text boxes showing the current axis limits are updated
  2. The prying eyes that are centered on the axes will move to the new axis center

This demo also uses Name=Value syntax and emoji text objects !

Create app

h.fig = uifigure(Name="LimitsChangedFcn Demo", ...
    Resize="off");
h.fig.Position(3:4) = [500,260];
movegui(h.fig)
h.ax = uiaxes(h.fig,...
    Units="pixels", ...
    Position=[200 26 250 208], ...
    Box="on");
grid(h.ax,"on")
title(h.ax,"I'm following you!")
h.eyeballs = text(h.ax, .5, .5, ...
    char([55357 56385 55357 56385]), ...
    HorizontalAlignment="center", ...
    FontSize=40);
h.label = uilabel(h.fig, ...
    Text="Axis limits", ...
    Position=[25 212 160 15], ...
    FontWeight="bold",...
    HorizontalAlignment="center");
h.xtxt = uitextarea(h.fig, ...
    position=[25 191 160 20], ...
    HorizontalAlignment="center", ...
    WordWrap="off", ...
    Editable="off",...
    FontName=get(groot, 'FixedWidthFontName'));
h.ytxt = uitextarea(h.fig, ...
    position=[25 165 160 20], ...
    HorizontalAlignment="center", ...
    WordWrap="off", ...
    Editable="off", ...
    FontName=get(groot, 'FixedWidthFontName'));
h.label = uilabel(h.fig, ...
    Text=['X',newline,newline,'Y'], ...
    Position=[10 170 15 38], ...
    FontWeight="bold");

Set LimitsChangedFcn of x and y axes

h.ax.XAxis.LimitsChangedFcn = @(hObj,data)limitsChangedCallbackFcn(hObj,data,h,'x');
h.ax.YAxis.LimitsChangedFcn = @(hObj,data)limitsChangedCallbackFcn(hObj,data,h,'y');

Update text fields

xlim(h.ax, [-100,100])
ylim(h.ax, [-100,100])

Define LimitsChangedFcn

function limitsChangedCallbackFcn(rulerHand, limChgData, handles, xy)
% limitsChangedCallbackFcn() responds to changes to x or y axis limits.
% - rulerHand: Ruler handle for x or y axis that was changed (not used in this demo)
% - limChgData: LimitsChanged data structure
% - handles: structure of App handles
% - xy: either 'x' or 'y' identifying rulerHand
switch lower(xy)
    case 'x'
        textHandle = handles.xtxt;
        positionIndex = 1; 
    case 'y'
        textHandle = handles.ytxt;
        positionIndex = 2; 
    otherwise
        error('xy is a character ''x'' or ''y''.')
end
% Update text boxes showing rounded axis limits
textHandle.Value = sprintf('[%.3f, %.3f]',limChgData.NewLimits);
% Move the eyes to the new center position
handles.eyeballs.Position(positionIndex) = limChgData.NewLimits(1)+range(limChgData.NewLimits)/2; % for linear scales only!
drawnow
end

See attached mlx file for a copy of this thread.

Highlight Icon image

We will be hosting a seminar on MATLAB Grader, the product I manage at MathWorks, on April 21st at 7am EDT. If you are interested in adding autograding capabilities for #MATLAB to your course, MOOC, textbook, or learning environment and have questions, please join this seminar and take part in the live Q&A with the product team the following week. #autograding #assessments #onlineassessment #onlineteaching

MathWorks Seminar: Autograded Assessments with MATLAB Grader & LMS Integration