メインコンテンツ

結果:


Adam Danz
Adam Danz
最後のアクティビティ: 2020 年 4 月 10 日

Do date ranges from two different timetables intersect?

Is a specific datetime value within the range of a timetable?

Is the range of row times in a timetable within the limits of a datetime array?

Three new functions in r2020a will help to answer these questions.

In these function inputs, TT is a timetable and input #2 is one of the following:

The tf output is a logical scalar indicating pass|fail and the whichRows output is a logical vector identifying the rows of TT that are within the specified time range.

How do these functions differ?

Let's test all 3 functions with different time ranges and a timetable of electric utility outages in the United States, provided by Matlab. The first few rows of outages.csv are shown below in a timetable. You can see that the row times are not sorted which won't affect the behavior of these functions.

8×5 timetable
     OutageTime          Region         Loss     Customers     RestorationTime            Cause       
  ________________    _____________    ______    __________    ________________    ___________________
  2002-02-01 12:18    {'SouthWest'}    458.98    1.8202e+06    2002-02-07 16:50    {'winter storm'   }
  2003-01-23 00:49    {'SouthEast'}    530.14    2.1204e+05                 NaT    {'winter storm'   }
  2003-02-07 21:15    {'SouthEast'}     289.4    1.4294e+05    2003-02-17 08:14    {'winter storm'   }
  2004-04-06 05:44    {'West'     }    434.81    3.4037e+05    2004-04-06 06:10    {'equipment fault'}
  2002-03-16 06:18    {'MidWest'  }    186.44    2.1275e+05    2002-03-18 23:23    {'severe storm'   }
  2003-06-18 02:49    {'West'     }         0             0    2003-06-18 10:54    {'attack'         }
  2004-06-20 14:39    {'West'     }    231.29           NaN    2004-06-20 19:16    {'equipment fault'}
  2002-06-06 19:28    {'West'     }    311.86           NaN    2002-06-07 00:51    {'equipment fault'}

The range of times in utility.csv is depicted by the gray timeline bar in the plot below labeled "Timetable row times". The timeline bars above it are various time ranges or scalar datetime values used to test the three new functions.

The three columns of checkboxes on the right of the plot show the results of the first output of each function, tf, for each time range.

The time ranges were created by the timerange function using the syntax timerange(startTime,endTime). The default intervalType in timerange() is 'openright' which means that datetimes are matched when they are equal to or greater than startTime and less than but not equal to endTime. The scalar datetime values were created with datetime().

The colorbar along with the colored points at the bottom of each timeline bar show the row numbers of timetable TT that were selected by the whichRows output of the three functions.

The containsrange() function returns true when all of the time range values are within the timetable including the timetable's minimum and maximum datetime.

The overlapsrange() function returns true when any of the time range values are with the timetable's range.

The withinrange() function returns true only when all of the timetable's datetime values are within the time range values. A careful observer may see that comparison number 1 is false even though that time range is exactly equal to the timetable's row time range. This is because the default value for intervalType in the timerange() function is 'openright' which does not match the end values if they are equal. If you change the intervalType to 'closed' the withinrange result for comparison 1 would be true.

The scalar datetime values for comparisons 8, 9 and 10 are all exact matches of datetimes within the timetable and result in a single match in the whichRows output. The datetime values for comparisons 7 and 11 do not match any of the timetable row times and the values in whichRows are all false even though comparison 7 is within the timetable range. For all three tests, the whichRows outputs are identical.

---------------------------------------------------------------

Here is the code used to generate this data, test the functions, and produce the plot.

% Read in the outage data as a table and convert it to a timetable TT.
T = readtable('outages.csv');
TT = table2timetable(T);
% Look at the first few rows.
head(TT)
% Show that row time vector is not sorted.
issorted(TT)
% Get the earliest and latest row time.
outageTimeLims = [min(TT.OutageTime), max(TT.OutageTime)];
% Define time ranges to test [start,end] or scalar times [datetime, NaT]
% The scalar times must be listed after time ranges.
dateRanges = [ % start, end
    outageTimeLims;                                 % original data
    outageTimeLims;                                 % equal time range
    datetime(2005,2,1), datetime(2011,2,1);         % all within
    datetime(1998,3,16), datetime(2018,4,11);       % starts before, ends after
    datetime(2000,1,1), datetime(2010,4,11);        % starts before, ends within
    datetime(2009,1,15), datetime(2019, 4,7);       % starts within, ends after
    datetime(2015,6,15), datetime(2019,12,31);      % all outside
    datetime(2008,6,6), NaT;                        % 1-value, inside, not a member
    [TT.OutageTime(find(year(TT.OutageTime)==2010,1)), NaT] % 1 value, inside, is a member
    outageTimeLims(1), NaT;                         % 1-value, on left edge
    outageTimeLims(2), NaT;                         % 1-value, on right edge
    datetime(2000,6,6), NaT;                        % 1-value, outside
    ];
nRanges = size(dateRanges,1);
dateRangeLims = [min(dateRanges,[],'all'), max(dateRanges,[],'all')];
% Set up the figure and axes
uifig = uifigure('Name', 'Timetable_intersection_demo', 'Resize', 'off');
uifig.Position(3:4) = [874,580];
movegui(uifig,'center')
uiax = uiaxes(uifig, 'Position', [0,0,uifig.Position(3:4)], 'box', 'on', 'YAxisLocation', 'right',...
    'ytick', -.5:1:nRanges, 'YTickLabel', [], 'ylim', [-3.5, nRanges], 'FontSize', 18);
hold(uiax, 'on')
grid(uiax, 'on')
uiax.Toolbar.Visible = 'off';
% Add axes labels & title
title(uiax, strrep(uifig.Name,'_',' '))
xlabel(uiax, 'Timeline')
ylab = ylabel(uiax, 'Comparison number');
set(ylab, 'Rotation', -90, 'VerticalAlignment', 'Bottom')
% Add the timetable frame
fill(uiax, outageTimeLims([1,2,2,1]), [-.7,-.7,nRanges-.3,nRanges-.3] , 0.85938*[1,1,1], ... %gainsboro
    'EdgeColor', 0.41016*[1,1,1], 'LineStyle', '--', 'LineWidth', 1.5, 'FaceAlpha', .25)     %dimgray
% Set xtick & xlim after x-axis is converted to datetime
range = @(x)max(x)-min(x); 
uiax.XLim = dateRangeLims + range(dateRangeLims).*[-.01, .40];
uiax.XTick = dateshift(dateRangeLims(1),'start','Year') : calyears(2) : dateshift(dateRangeLims(2),'start','Year','next');
xtickformat(uiax,'yyyy')
% Set up timeline plot
lineColors = [0.41016*[1,1,1]; lines(nRanges-1)]; %dimGray
uiax.Colormap = parula(size(TT,1));
tfUniCodes = {char(09745),char(09746)}; %{true, false} checkbox characters
barHeight = 0.8;
rightMargin = [max(dateRangeLims),max(uiax.XLim)];
tfCenters = linspace(rightMargin(1),rightMargin(2),5);
tfCenters([1,end]) = [];
intervalType = 'openright';  % open, closed, openleft openright(def);  see https://www.mathworks.com/help/matlab/ref/timerange.html#bvdk6vh-intervalType
% Loop through each row of dateRanges
for i = 0:nRanges-1
    % Plot timeline bar
    pObj = fill(uiax, dateRanges(i+1,[1,2,2,1]), i+[-barHeight,-barHeight,barHeight,barHeight]/2, lineColors(i+1,:), 'FaceAlpha', .4);
      % Evaluate date ranges and single values differently
      if any(isnat(dateRanges(i+1,:)))
          % Test single datetime
          tr = dateRanges(i+1,~isnat(dateRanges(i+1,:)));
          set(pObj, 'LineWidth', 3, 'EdgeAlpha', .6, 'EdgeColor', lineColors(i+1,:))
      else
          % Test date range
          tr = timerange(dateRanges(i+1,1), dateRanges(i+1,2),intervalType);
      end
      % Create timerange obj and test for intersections
      [tf(1), whichRows{1}] = containsrange(TT,tr);
      [tf(2), whichRows{2}] = overlapsrange(TT,tr);
      [tf(3), whichRows{3}] = withinrange(TT,tr);
      % Confirm that all 'whichRows' are equal
      assert(isequal(whichRows{1},whichRows{2},whichRows{3}), 'Unequal whichRows outputs.')
      if i>0
          % Add pass/fail checkboxes
          text(uiax, tfCenters(tf), repmat(i,1,sum(tf)), repmat(tfUniCodes(1),1,sum(tf)), ...
              'HorizontalAlignment', 'Center', 'Color', [0 .5 0], 'FontSize', 36, 'FontWeight', 'Bold')
          % Fail checkboxes
          text(uiax, tfCenters(~tf), repmat(i,1,sum(~tf)), repmat(tfUniCodes(2),1,sum(~tf)), ...
              'HorizontalAlignment', 'Center', 'Color', [1 0 0], 'FontSize', 36, 'FontWeight', 'Bold')
          % Plot the TT row number matches
          scatter(uiax, TT.OutageTime(whichRows{1}), repmat(i-barHeight/2+.1,1,sum(whichRows{1})), ...
              10, uiax.Colormap(whichRows{1},:), 'filled', 'MarkerFaceAlpha', 0.2)
      else
          % add stripes to reference bar
          xHatch = linspace(dateRanges(i+1,1)-days(2), dateRanges(i+1,2)+days(2), 20);
          yHatch = repmat(unique(pObj.YData), 1, 19);
          plot(uiax, [xHatch(1:end-1);xHatch(2:end)], yHatch, '-', 'Color', [1 1 1 .5], 'LineWidth', 4)
          pObj.FaceAlpha = .9;
          text(uiax, mean(outageTimeLims), 0, 'Timetable row times', 'FontSize', 20, ...
              'HorizontalAlignment', 'Center', 'VerticalAlignment', 'middle', 'FontWeight', 'Bold')
      end
  end
% Draw frame around checkboxs for duration comparisons and label intervalType
rectEdges = linspace(rightMargin(1),rightMargin(2),33);
nDurations = sum(~isnat(dateRanges(:,2)))-1;
fill(uiax, rectEdges([6,end-5,end-5,6]), [.4 .4 nDurations+[.4,.4]], 'w', ...
    'FaceAlpha', 0, 'LineWidth', 1.5, 'EdgeColor', 0.41016*[1,1,1]) % dimgray
text(uiax, rectEdges(6), nDurations/2+.5, sprintf('intervalType: %s', intervalType), 'FontSize', 16, ...
    'HorizontalAlignment', 'Center', 'VerticalAlignment', 'Bottom', 'Rotation', 90)
% Add text labels for checkboxes and comparison number
text(uiax, tfCenters, [.5 .5 .5], {'containsrange ', 'overlapsrange ', 'withinrange '}, 'Fontsize', 22, 'Rotation', 90, ...
    'HorizontalAlignment', 'right', 'FontWeight', 'b')
text(uiax, repmat(rightMargin(2)-range(xlim(uiax))*.02,1,nRanges-1), 1:nRanges-1, cellstr(num2str((1:nRanges-1)')), ...
    'HorizontalAlignment', 'Right', 'FontSize', 16)
% Add color bar; position it under the timetable bar (must be done after all other axes properties are set)
% requires coordinate tranformation from data units to fig position units.
cb = colorbar(uiax, 'Location', 'South', 'TickDirection', 'Out', 'YAxisLocation', 'Bottom', 'FontSize', 11);
caxis(uiax, [1,size(TT,1)])
cb.Position(3) = range(outageTimeLims)/range(xlim(uiax))  * (uiax.InnerPosition(3)/uifig.Position(3));
cb.Position(1) = ((outageTimeLims(1)-min(xlim(uiax)))/range(xlim(uiax)) * uiax.InnerPosition(3) + uiax.InnerPosition(1)) / uifig.Position(3); 
cb.Position(4) = 0.008;
cb.Position(2) = ((-barHeight-min(ylim(uiax))-.5)/range(ylim(uiax)) * uiax.InnerPosition(4) + uiax.InnerPosition(2)) / uifig.Position(4);
ylabel(cb, 'Timetable row number')
David
David
最後のアクティビティ: 2021 年 4 月 26 日

The following is a list of updates and new features for File Exchange and Cody.

New Features

  • (Coming soon) Support for GitHub releases added to File Exchange - Stay tuned for an upcoming announcement later this month.
  • 2 new Cody problem groups - Visit Cody to see the new MATLAB Basics and Beyond the Basics problem groups.

Let us know what you think about these new features by replying below.

David
David
最後のアクティビティ: 2020 年 4 月 8 日

Take a look at this handy cheatsheet from Peijin Zhang, a PhD student of solar radio at USTC, China. This is especially helpful for those preparing figures for a paper.

https://github.com/Pjer-zhang/matlabPlotCheatsheet

Do you know of any other cheatsheets for MATLAB?

goc3
goc3
最後のアクティビティ: 2020 年 4 月 6 日

Cody has a wealth of problem groups that allow users of various skill levels to improve programming skills vis-à-vis MATLAB in an engaging way.

I would like to highlight the Draw Letters group, composed of problems created by Majid Farzaneh.

If you haven't yet visited Cody or solved that problem group, I would recommend that you head over there now. What are you waiting for?

Naomi Fernandes
Naomi Fernandes
最後のアクティビティ: 2020 年 4 月 6 日

Looking for solutions to move your course online? zyBooks and MathWorks have teamed up to provide free access to the Introduction to MATLAB zyBook for the remainder of the Spring 2020 semester.

This web-based book presents a comprehensive introduction to MATLAB through interactive questions, animations, and automated MATLAB assessment. Benefits include:

  • Access the textbook, homework, and practice from one location
  • Put theory into action through an engaging, learn-by-doing approach
  • Improve student learning with instant, contextual feedback
  • Save time grading with automated MATLAB assessment using MATLAB Grader
  • See real-time analysis of class and student performance
  • Create custom MATLAB assignments using zyLabs
  • Use proven, prebuilt interactive questions and animations

Learn more at: https://www.zybooks.com/covid-19-care-package/

Jiro Doke
Jiro Doke
最後のアクティビティ: 2023 年 8 月 24 日

MATLAB Online lets students run MATLAB without having to install the software on the computer. All you need is a web browser and an internet connection.

I would love to hear comments and experiences of using MATLAB Online.

The Webinar has ended, but you can view the recording here on YouTube.

MathWorks has developed several cloud-based tools to enable instructors and students to have access for teaching and learning anytime, anywhere. Join us for a free webinar with Dr. Elvira Osuna-Highley where we’ll discuss these tools, how they fit together to support your course development and delivery workflow, and how to use them immediately in your online course.

We will discuss several resources including:

• Accessing MATLAB Online and MATLAB Drive Anytime, Anywhere

• Leveraging interactive content with self-paced courses, MATLAB Apps, and Live Scripts

• Mentoring students at scale with automated assessment and feedback in MATLAB Grader

• Connecting students with the community by participating in the MATLAB user community

Thank you to IFEES, GEDC and IUCEE for sponsoring this series to help support educators across the world in moving their courses online.

David
David
最後のアクティビティ: 2020 年 5 月 6 日

We have created a new distance learning community for educators who are teaching remotely or online using MathWorks tools. It houses resources, such as articles, code examples, and videos, as well as an area where community members can ask questions or hold discussions around best practices in distance learning. Jiro Doke , who also writes for the File Exchange Pick of the Week blog, will be moderating this community.

We encourage you to visit the new community and share best practices, examples, and ask questions.

David
David
最後のアクティビティ: 2020 年 3 月 30 日

We have created a new page in MATLAB Answers that aggregates the most frequently asked MATLAB questions (FAQs). FAQs are common and a good starting point for anyone learning something new and having them all in one place can be a useful resource. Our new FAQ page lists the top 100 MATLAB questions asked and answered in MATLAB Central . They are grouped into the following 9 categories:

  • Data Import and Analysis
  • Graphics: Basics
  • Graphics: Objects
  • Installation and Licensing
  • Language Fundamentals: Basics
  • Language Fundamentals: Matrices and Arrays
  • Language Fundamentals: Operators and Elementary Operations
  • Mathematics
  • Programming

I recommend that everyone scans the new FAQ page as you might find some useful tips.

We will be updating the FAQ page regularly as new questions are asked in the community. We welcome any feedback you have.

Chad Allie
Chad Allie
最後のアクティビティ: 2020 年 3 月 30 日

Hello Distance Learning Community!

I am hoping to hear from any academics in how MATLAB's online resources have helped you during this difficult time of transition to online courses:

- Have you had any issues or difficulties with getting started with our online tools?

- Do you see any areas of improvement that could better serve your course in an online environment?

- Do you have any stories to share of how these online tools have helped you to run your class and improve it for the future?

Thank you and stay well!

Chad Allie

Education Customer Success (USA Southwest)

Jiro Doke
Jiro Doke
最後のアクティビティ: 2020 年 3 月 30 日

Hello everyone,

I’m Jiro, and I’m part of the Education Customer Success group at MathWorks. We help academics, students, and institutions achieve success through the use of our tools. I will be the moderator for this new community of distance learning.

As many academic institutions are moving their classes online, we hope that this community will help instructors connect with others who are in the same situation. This community site gathers various resources and information that will be useful for teaching with MATLAB and Simulink in a distance learning setting. We have a number of MathWorks employees monitoring this community, but we want this to be a place for the community to come together. The hope is that the community will grow and the resources gathered here will grow with it.

I encourage you to share best practices ( Discussions ), ask questions ( MATLAB Answers ), and share examples ( File Exchange ).

As a first question, what course are you teaching (or planning to teach) online?

praveen kumar
praveen kumar
最後のアクティビティ: 2020 年 3 月 26 日

Hello friends i have strugled to develope codes in matlab and spent ample time in converting the available codes to my area . If any of the researcher are interested to share their codes with me are welcomed and collabarations are welcomed ...currenty i need a basic code in unit commitment using real coded and binary coded for Security contrained and integrating Reneweable energy .. I too will share my codes because world is going to vanish soon so my knowledge should spread across the globe

with rds s.praveen kumar email:praveenaups777@gmail.com

David
David
最後のアクティビティ: 2020 年 3 月 25 日

Check out this pick of the week from Emma Gau. Emma's submission is featured on the Live Script gallery. Check out the blog post to see why Owen picked it.

Tony Lennon
Tony Lennon
最後のアクティビティ: 2020 年 3 月 25 日

Check out this short video on the new features in Simulink R2020a . What's your favorite new feature?

Arkadiy Turevskiy
Arkadiy Turevskiy
最後のアクティビティ: 2020 年 3 月 20 日

Just wanted to post a link to this video we recently published on YouTube:

PID Controller tuning for a buck converter

Let me know what you think. Arkadiy

Hi everyone,

I am trying to control an actuator with brushless DC Motor in Simulink. At one point, I am in need of the motor rotation and the only parameter available to me is the duty cycle and the direction of rotor. I knew that it is not possible to calculate rotation from duty cycle. In case if some one have idea about this or some suggestions, could you please share with me

Thanks in advance

SAURABH KUMAR
SAURABH KUMAR
最後のアクティビティ: 2020 年 11 月 15 日

Hello,

I am trying to simulate a PMSM, which has a Quasi sinusoidal back-emf waveform. Is there any way I can define the back emf to be anything other than Sinusoidal/Trapezoidal?

Thanks in advance. Saurabh Kumar

David
David
最後のアクティビティ: 2020 年 3 月 25 日

Check out this pick of the week from Will. Steve's progressbar submission has been around since 2005 and still runs perfectly. Check out the blog post to see why Will picked it.

big Min
big Min
最後のアクティビティ: 2020 年 3 月 27 日

Recently, I have been learning the mathematical modeling of switching converters. Looking for a lot of data, I know that the current loop control mainly includes peak current, valley current and average current control methods. The detailed process of peak current modeling is found in the book "modeling, control and digital realization of switch converter". However, my brother has not found the detailed introduction of average current modeling. I would like to ask you brother and sister have any good information recommendation, the best is books (the most detailed explanation). Thank you very much!

I have issue with the design that i have downloaded from mathwork community. how to solve regarding this matter

Failed to load library 'powerlib_models' referenced by 'mcupqc/Subsystem/Voltage Measurement/model' Component:Simulink | Category:Model error Failed to load library 'powerlib_models' referenced by 'mcupqc/Three-Phase V-I Measurement/model' Component:Simulink | Category:Model error Failed to load library 'powerlib_models' referenced by 'mcupqc/Three-Phase V-I Measurement1/model' Component:Simulink | Category:Model error Failed to load library 'powerlib_models' referenced by 'mcupqc/Three-Phase V-I Measurement2/model' Component:Simulink | Category:Model error Failed to load library 'powerlib_models' referenced by 'mcupqc/Three-Phase V-I Measurement3/model' Component:Simulink | Category:Model error Failed to load library 'powerlib_models' referenced by 'mcupqc/Three-Phase V-I Measurement4/model' Component:Simulink | Category:Model error Failed to load library 'powerlib_models' referenced by 'mcupqc/Three-Phase V-I Measurement5/model' Component:Simulink | Category:Model error Failed to load library 'powerlib_models' referenced by 'mcupqc/Three-Phase V-I Measurement6/model' Component:Simulink | Category:Model error