主要内容

搜索


Here's a short article describing how educators from UNSW have used Live Scripts to help students understand mathematical models. Interactive live scripts allow students to experiment and understand concepts through trial and error. The article also explains how the scripts helped provide an enriched online learning experience for the students.

https://www.education.unsw.edu.au/using-matlab-live-scripts-develop-students-understanding-mathematical-models-and-analysis

Do you use Live Scripts in your teaching?

Prior to r2020b the height (number of rows) and width (number of columns) of an array or table can be determined by the size function,

array = rand(102, 16);
% Method 1
[dimensions] = size(array);
h = dimensions(1);
w = dimensions(2);
% Method 2
[h, w] = size(array); %#ok<*ASGLU>
% or
[h, ~] = size(array);
[~, w] = size(array);
% Method 3
h = size(array,1);
w = size(array,2);

In r2013b, the height(T) and width(T) functions were introduced to return the size of single dimensions for tables and timetables.

Starting in r2020b, height() and width() can be applied to arrays as an alternative to the size() function.

Continuing from the section above,

h = height(array)
% h =  102
w = width(array)
% w =  16

height() and width() can also be applied to multidimensional arrays including cell and structure arrays

mdarray = rand(4,3,20);
h = height(mdarray)
% h =  4
w = width(mdarray)
% w =  3

The expanded support of the height() and width() functions means,

  1. when reading code, you can no longer assume the variable T in height(T) or width(T) refers to a table or timetable
  2. greater flexibility in expressions such as the these, below
% C is a 1x4 cell array containing 4 matrices with different dimensions
rng('default')
C = {rand(5,2), rand(2,3), rand(3,4), rand(1,1)};
celldisp(C)
% C{1} =
%       0.81472      0.09754
%       0.90579       0.2785
%       0.12699      0.54688
%       0.91338      0.95751
%       0.63236      0.96489
% C{2} =
%       0.15761      0.95717      0.80028
%       0.97059      0.48538      0.14189
% C{3} =
%       0.42176      0.95949      0.84913      0.75774
%       0.91574      0.65574      0.93399      0.74313
%       0.79221     0.035712      0.67874      0.39223
% C{4} =
%       0.65548

What's the max number of rows in C?

maxRows1 = max(cellfun(@height,C))         % using height()
% maxRows1 =  5;
maxRows2 = max(cellfun(@(x)size(x,1),C))   % using size()
% maxRows2 =  5; 

What's the total number of columns in C?

totCols1 = sum(cellfun(@width,C))          % using width()
%totCols1 =  10
totCols2 = sum(cellfun(@(x)size(x,2),C))   % using size(x,2)
% totCols2 =  10

Attached is a live script containing the content of this post.

Hi All,

Using the PMLSM SimScape block for my FOC PMLSM model - PMLSM

In the example ee_pmlsm_drive.slx which i have based my FOC architedure on, have a few questions please.

There is a gain block after the outer loop velocity controller (iq_Ref), which is the inverse of the Force constant (Kt) shown as (2/3*Np*PM) in the literature. This is also used in the PMSM FOC model, placed after the torque limiter Tq to iq_Ref. Why is this inverse Kt gain added to the idq_ref signal? Does this cancel Kt if its used in the Force Equation?

Previous help posts regarding the Force Constant (Kt), imply emitting the constant (3/2) in Kt. Also in the PMLSM help center document states Ke, Kt and Flux linkage are equal. Does this simplification apply to the translational machine counterpart SimScape block?

I have tried to look into the SimScape block code of the PMLSM to confirm, how do i look under the mask to check the Force equation for the PMLSM to confirm Kt and Ke used in this model?

Any help would be great as this is holding up Validation of my "small signal" linear PMLSM model against the SimScape PMLSM block model.

Thanks

Patrick

hasan ramzani
hasan ramzani
上次活动时间: 2020-10-5

I'm a student. Please send me a simulation of a residential microgrid. I need this simulation for my university thesis. My thesis is about economically efficient operation of a residential microgrid using the mopso algorithm.

IFM
IFM
上次活动时间: 2020-10-2

I often code snippets to students in the question description. I would like the students to be able to copy and paste these from the description into their solution, obviously all on the same web page. I thought this was the case before, but now Ctrl+C/V do not work and when I right click there is no copy/paste options. Is this not possible?

'
The Matlab r2020b release introduces the new horizontal ('_') and vertical (' | ') line marker symbols that are centered around the coordinate similarly to the plus marker ('+').
plot(x,y,'_')
plot(x,y,'|')
See the attached Live Script to reproduce all plots in this post.
'
Use case example 1: Days in August 2020 that COVID-19 cases (vertical ticks) and number of tests (horizontal ticks) increased from the previous day in countries with populations greater than 100M (4 countries eliminated for incomplete data).
'
Use case example 2: (An alternative to stacked bar plots) Number of power outages in 2005 across regions of the USA, broken down by calendar quarters.

One great thing about IoT projects is they are connected to the internet, and that creates an opportunity to collaborate at a distance. Here are resources to help you teach classes that involve remote learning.

  • Record and visualize your experiment's data in ThingSpeak channels. For example, this public soil monitor channel shows measurements from a sensor connected to a plant. You can see the ThingSpeak example pages for help getting your experiment connected.

Figure 1: Fitvirus sample results.

When you can’t make it into the lab, use ThingSpeak to monitor and control your lab equipment for experiments and for teaching.

  • When you use ThingSpeak channel values to control your hardware modes, students can run experiments from home, and even collaborate with others to control devices and collect data for analysis.

Figure 2: Sample ThingSpeak lab model.

  • Build a simulation model to deploy on hardware and control it remotely. Watch this video to see how you can do both simulation and deployment in the same Simulink model. You can also download the models used in the video.
  • Use ThingSpeak to analyze your data. Use the provided code templates (like this one for removing outliers from wind speed data) or custom MATLAB code to filter and analyze your data and schedule it to run at regular intervals.

regularFlag = isregular(data,'Time')

Hi All,

Looking for guidance on how to represent a PMSM 3-Phase Converter (DC bus to AC) as a simply 1st Order Transfer Function in my Simulink model.

Researching this, have found we can show the Power Converter as a simple gain and time delay such as G_inv(s) = K_Inv/(1 + T_inv s)

The gain requires V_cm, which is the control voltage, is this control voltage the "Forward Voltage, Vf" in Switching Devices tab in the block?

Is my assumption for the tf for the converter correct?

Thanks

Patrick

Please join Loren Shure for her live sessions on the MATLAB YouTube channel starting October 1st and continuing through November 19th. You know Loren from her popular blog Loren on the Art of MATLAB.

IFM
IFM
上次活动时间: 2020-9-23

I get students to create some figures in MATLAB Grader. Is there anyway the students can save the figure on their computer? I have tried savefig and that doesn't seem to do anything.

Add a subtitle

Multi-lined titles have been supported for a long time but starting in r2020b, you can add a subtitle with its own independent properties to a plot in two easy ways.

  1. Use the new subtitle function: s=subtitle('mySubtitle')
  2. Use the new second argument to the title function: [t,s]=title('myTitle','mySubtitle')
figure()
tiledlayout(2,2)
% Method 1
ax(1) = nexttile;
th(1) = title('Pupil size'); 
sh(1) = subtitle('Happy faces');
ax(2) = nexttile;
th(2) = title('Pupil size'); 
sh(2) = subtitle('Sad faces');
% Method 2
ax(3) = nexttile;
[th(3), sh(3)] = title('Fixation duration', 'Happy faces'); 
ax(4) = nexttile;
[th(4), sh(4)] = title('Fixation duration', 'Sad faces'); 
set(ax, 'xticklabel', [], 'yticklabel', [],'xlim',[0,1],'ylim',[0,1])
% Set all title colors to orange and subtitles colors to purple.
set(th, 'Color', [0.84314, 0.53333, 0.1451])
set(sh, 'Color', [0, 0.27843, 0.56078])

Control title/Label alignment

Title and axis label positions can be changed via their Position, VerticalAlignment and HorizontalAlignment properties but this is usually clumsy and leads to other problems when trying to align the title or labels with an axis edge. For example, when the position units are set to 'data' and the axis limits change, the corresponding axis label will change position relative to the axis edges. If units are normalized and the axis position or size changes, the corresponding label will no longer maintain its relative position to the axis, and that's assuming the normalized position was computed correctly in the first place.

Starting in r2020b, title and axis label alignment can be set to center|left|right, relative to the axis edges.

  • TitleHorizontalAlignment is a property of the axis: h.TitleHorizontalAlignment='left';
  • LabelHorizontalAlignment is a property of the ruler object that defines the x | y | z axis: h.XAxis.LabelHorizontalAlignment='left';
% Create data
x = randi(50,1,100)'; 
y = x.*[.2, -.2] + (rand(numel(x),2)-.5)*10; 
gray = [.65 .65 .65];
% Plot comparison between columns of y
figure()
tiledlayout(2,2,'TileSpacing','none')
ax(1) = nexttile(1);
plot(x, y(:,1), 'o', 'color', gray)
lsline
ylabel('Y1 (units)')
title('Regression','Y1 & Y2 separately')
ax(2) = nexttile(3);
plot(x, y(:,2), 'd', 'color', gray)
lsline
xlabel('X Label (units)')
ylabel('Y2 (units)')
grid(ax, 'on')
linkaxes(ax, 'x')
%  Move title and labels leftward
set(ax, 'TitleHorizontalAlignment', 'left')
set([ax.XAxis], 'LabelHorizontalAlignment', 'left')
set([ax.YAxis], 'LabelHorizontalAlignment', 'left')
% Combine the two comparisons into plot and flip the second 
% y-axis so trend are in the same direction
ax(3) = nexttile([2,1]);
yyaxis('left')
plot(x, y(:,1), 'o')
ylim([-6,16])
lsline
xlabel('X Label (units)')
ylabel('Y1 (units) \rightarrow')
yyaxis('right')
plot(x, y(:,2), 'd')
ylim([-16,6])
lsline
ylabel('\leftarrow Y2 (units)')
title('Direct comparison','(Y2 axis flipped)')
set(ax(3),  'YDir','Reverse')
% Align the ylabels with the minimum axis limit to emphasize the
% directions of each axis. Keep the title and xlabel centered
ax(3).YAxis(1).LabelHorizontalAlignment = 'left';
ax(3).YAxis(2).LabelHorizontalAlignment = 'right';
ax(3).TitleHorizontalAlignment = 'Center';       % not needed; default value.
ax(3).XAxis.LabelHorizontalAlignment = 'Center'; % not needed; default value.
It's pretty odd how a solution that uses more characters than usual can be the "leading solution" of a Cody problem and have the least size. Compare these two codes that find the sum of integers from 1 to 2^x, which one uses fewer characters, thus should be the better solution?
function y = sum_int(x)
regexp '' '(?@y=sum(1:2^x);)'
end
function ans = sum_int(x)
sum(1:2^x)
end

Dear power electronics control community,

Since I have not solved the problem and have not found an answer to why I receive such an output, I would be happy when you could help me out. The actual project is much more extensive but easy schematic of what I want to do is here:

For that, I am using 2-level PWM generator: https://se.mathworks.com/help/physmod/sps/powersys/ref/pwmgenerator2level.html In the DC-link (DC voltage after the converter) the DC voltage output should be more-less constant (with a little noise) but right now it very far away from the desired output:

Does anyone have a idea what might cause this problem?

Jiro Doke
Jiro Doke
上次活动时间: 2020-8-21

Take a look at this video on remote access robotics lab. It allows students to submit algorithms and have them run on a robot completely remotely.

Robotarium

Here (16:56) is where the submission process is explained.

Professor Christophe Demaziere from Chalmers University of Technology, Sweden created a short course on nuclear reactor modeling.

  • The course followed a flipped and hybrid approach last year but will most likely be taught entirely online in future due to Covid-19 pandemic.
  • MATLAB Grader greatly facilitates the Online nature of Christophe's courses.
  • Student Feedback was also very positive saying that they learned better compared to the traditional approach.

More details in the article

I'm trying to list out some videos, courses, and other links to learn more about Machine and Deep Learning. Here are some links to getting started with AI/Machine Learning/Deep Learning with MATLAB:

Artificial Intelligence:

Machine Learning:

Data Analytics:

Neural Networks and Deep Learning:

If any of you are using other resources from the MathWorks website or elsewhere, please consider adding it below as a comment.

Thanks!

Hello,

I am a student. I am currently looking into graph neural networks (GNNs). My domain is electrical power systems. In electrical power systems, it is extremely important that we get an accurate desired output numerical value of electrical data from a neural network.

1) I have a basic question. Consider an electrical grid network of nodes. I am trying to learn this electrical grid network data using Graph Neural Network (GNN). Every node of a GNN accumulates data from neighboring nodes, then processes it by a few steps of an algorithm, and passes it to the next layer. Finally, data is passed through a non-linearity and then to the output layer of the GNN.

But, if I feed electrical data to the above process, the original value of data at every node gets manipulated by several processing operations, and especially after passing the manipulated data through a non-linearity at the final stage, the output is obtained only in the form of 1's and 0s. Hence, the original electrical data value at every node is totally lost. On the contrary, I am expecting an output of an "accurate" value of electrical data similar to original value electrical data at every node of the network.

How to address the above problem? Please explain systematically if possible. This is a genuine basic question.

2) Also, does anyone have a clue, why Graph Neural Networks (GNNs) have not been introduced yet as a toolbox or in general in Matlab?

Help and opinion on above questions would be greatly appreciated.

Hi Everyone, I am trying to simulate the third-order model of the synchronous generator (figure below). but I have no idea how to do this. Any help would be great.