基于matlab实现两条曲线之间的填充阴影区域

✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,matlab项目合作可私信。

🍎个人主页:Matlab科研工作室

🍊个人信条:格物致知。

更多Matlab仿真内容点击👇

智能优化算法       神经网络预测       雷达通信       无线传感器        电力系统

信号处理              图像处理               路径规划       元胞自动机        无人机 

⛄ 内容介绍

在数据可视化中,填充阴影区域是一种常见的技术,用于突出显示两条曲线之间的差异或关系。通过在曲线之间添加阴影,我们可以更清楚地展示数据的变化趋势,并帮助观众更好地理解数据之间的联系。

填充阴影区域在各种领域都有广泛的应用。例如,在金融领域,我们可以使用填充阴影来显示股票价格的波动范围。在气象学中,我们可以使用填充阴影来表示气温的变化范围。无论是在科学研究、商业分析还是其他领域,填充阴影区域都是一种有用的数据可视化技术。

要在两条曲线之间创建填充阴影区域,我们需要首先确定要显示的两条曲线。这些曲线可以是两个不同的数据集之间的关系,也可以是同一数据集中的两个不同变量之间的关系。无论是哪种情况,我们都需要确保这些曲线在同一个坐标系中。

一旦我们确定了要显示的曲线,我们就可以开始创建填充阴影区域了。首先,我们需要计算出曲线之间的差异或关系。这可以通过简单地将两条曲线相减来实现。然后,我们可以使用这些差异值来创建阴影区域。

在大多数数据可视化工具中,创建填充阴影区域是相对简单的。通常,我们可以使用图形库或软件中提供的特定函数或方法来实现。这些函数或方法通常会要求我们提供曲线的数据点,然后自动计算并绘制填充阴影区域。

当我们成功创建了填充阴影区域后,我们可以进一步调整其外观以满足我们的需求。我们可以选择不同的颜色、透明度或样式来使阴影区域更加醒目或与整体图形风格相匹配。

填充阴影区域不仅仅是为了美观,它还有助于传达数据的含义。通过突出显示两条曲线之间的差异,我们可以更好地理解数据之间的关系。这对于数据分析师、决策者和观众来说都非常重要,因为它可以帮助他们做出更准确的决策。

此外,填充阴影区域还可以用于表达不确定性。在某些情况下,我们可能无法准确地确定两条曲线之间的关系。在这种情况下,填充阴影区域可以表示我们的估计范围或不确定性水平。这对于预测和模型建立非常有用。

总而言之,填充阴影区域是一种有用的数据可视化技术,可以帮助我们更好地理解数据之间的关系和变化趋势。无论是在科学研究、商业分析还是其他领域,填充阴影区域都可以为我们提供有价值的见解。通过合理使用填充阴影区域,我们可以更好地传达数据的含义,帮助决策者做出更准确的决策。

⛄ 完整代码

FillBetweenAreaCurveThis chart lets you shade the area between 2 line plots. In this example, we create a chart that shades the area between sin-x and cos-x curvesx = linspace(0, 4 * pi, 100);y_sinx = sin(x);y_cosx = cos(x);Create a Basic ChartLet us start by creating a basic chart. Let us plot sin(x) and cos(x) on a chart and shade the area between these 2 curves.areaCurve = fillBetweenAreaCurve(x, y_sinx, y_cosx);Color Scheme of the Basic ChartBy default, we shade the area between 2 plots using 2 different colors. The shading color depends on the the line with the higher value. You can see that in the chart above, the all areas under the blue-colored line are shaded with light blue and vice versa. We can also change the color of a line, by default the shaded area's color will changeareaCurveLineColor = fillBetweenAreaCurve(x, y_sinx, y_cosx);areaCurveLineColor.Line1Color = 'm';Selective ShadingThe condition property is be very helpful if you want to engage in selective shading of the graph depending on certain values of x, y1 and y2. For instance, if you want to shade the same color for all value of x. You can create a condition that returns true always.areaCurveColor = fillBetweenAreaCurve(x, y_sinx, y_cosx, [0.2 0.4 0.1], 'Condition', @(x, y1, y2)true(1, numel(x)), "ShadeInverse", false);Note that the ShadeInverse property indicates if you would like to shade the parts of chart that are not satisfied by the Condition property. In fact any Inverse-* property indicates properties of the shaded area not satisfied by Condition.All the areas that satisfy the condition are colored using FaceColor property. Rest of the areas are shaded using 'InverseFaceColor' property. We can change these properties, after declaring the chartareaCurveCondition = fillBetweenAreaCurve(x, y_sinx, y_cosx, 'Condition',   @(x, y1, y2) x > 2 & x < 4);areaCurveCondition.FaceColor = 'm';areaCurveCondition.InverseFaceColor = 'y';It could be possible that user only requires the shaded area to be the one that satisfies the condition. In this you can set the Shade Inverse = falseareaCurveCondition2 = fillBetweenAreaCurve(x, y_sinx, y_cosx, 'Condition',   @(x, y1, y2) x > 2 & x < 4);areaCurveCondition2.ShadeInverse = false;Label Axes and Title of graphWe can also add special arguments to decorate the graph. For instance we can add title, labels of x-axis, y-axis and a legendareaCurveLabel = fillBetweenAreaCurve(x, y_sinx, y_cosx, ...    "Label1", "sin x", "Label2", "cos x", ...    "XLabel", "Time", "YLabel", "Amplitude", "Title", "Harmonics");We can also add Line specific properties like LineWidth, Color as key-value pairs in our arguments. In the example, we set the Color, LineWidth and LineStyle propertiesareaCurveLine1 = fillBetweenAreaCurve(x, y_sinx, y_cosx, ...    "Label1", "sin x", "Label2", "cos x", ...    "Line1Color", [0.5 0.2 0.5], "Line2LineWidth", 2 , "Line2LineStyle", "--" );The chart also supports composite boolean functions such as the one's specified in xFilter. In this case, which only shade values of x that lies between 2 and 10 and y1 <= y2c2 = fillBetweenAreaCurve(x, y_sinx, y_cosx, ...    "Label1", "sin x", "Label2", "cos x", ...    "Condition", @xFilter);Manual TriangulationCurrently, we optimize the construction of the chart by supporting manual triangulation before passing vertices data to patch. This ensures pacth can focus on shading the triangles and not calculating the triangle vertices. However, we can pass the vertices directly to patch object without calculating triangle vertices by setting OptimizePerformance = falseareaCurveOptimized = fillBetweenAreaCurve(x, y_sinx, y_cosx, "OptimizePerformance", false);function result = xFilter(x, y1, y2)    result = x >= 2 & x < 10 & y1 <= y2;end

classdef fillBetweenAreaCurve < matlab.graphics.chartcontainer.ChartContainer & ...        matlab.graphics.chartcontainer.mixin.Legend    % fillBetweenAreaCurve Shades the area between 2 curves    %     fillBetweenAreaCurve(x, y1, y2) shades the area between 2 lines    %     formed by (x,y1) and (x,y2)    %     %     fillBetweenAreaCurve(x, y1, y2, c) shades the area between 2    %     lines formed by (x,y1) and (x,y2) with color c    %         %     fillBetweenAreaCurve(__, Name, Value) specifies additional    %     options for the fillBetweenAreaCurve using one or more name-value    %     pair arguments. Specify the options after all other input    %     arguments    properties                % Data Properties of fillBetweenAreaCurve        XData (1,:) double = [];        Y1Data (1,:) double = [];        Y2Data (1,:) double = [];                % Properties for Fill Shape        FaceAlpha (1,1) double {mustBeInRange(FaceAlpha, 0, 1)} = 0.2;        % Properties for shading rest of the graph         ShadeInverse matlab.lang.OnOffSwitchState = 'on';        % Properties for Line 1         Line1LineWidth (1,1) double {mustBePositive(Line1LineWidth)} = 1;        Line1LineStyle (1,1) string {mustBeMember(Line1LineStyle, {'-', '--', ':', '-.'})} = '-';        Label1 (1,1) string = "Curve 1";               % Properties for Line 2        Line2LineWidth (1,1) double {mustBePositive(Line2LineWidth)} = 1;        Line2LineStyle (1,1) string {mustBeMember(Line2LineStyle, {'-', '--', ':', '-.'})}  = '-';        Label2 (1,1) string = "Curve 2";                % Propeties of the chart        XLabel (1,1) string = "";        YLabel (1,1) string = "";        Title (1,1) string = "";        % Triangulate polygon manually instead of asking patch to do it        OptimizePerformance matlab.lang.OnOffSwitchState = 'on';    end  properties (Dependent)      FaceColor;      InverseFaceColor;      Condition;      Line1Color;      Line2Color;  end   properties(Access = private,Transient,NonCopyable)        Line1Object matlab.graphics.chart.primitive.Line         Line2Object matlab.graphics.chart.primitive.Line         PatchObject matlab.graphics.primitive.Patch        InversePatchObject matlab.graphics.primitive.Patch        Validator ValidationFunctions = ValidationFunctions;   end   properties(Access = private)        FaceColorSetMode string = 'auto';        InverseFaceColorSetMode string = 'auto';        ConditionSetMode string = 'auto';        Line1ColorSetMode string = 'auto';        Line2ColorSetMode string = 'auto';        FaceColor_I {validatecolor} = [0, 0, 1];        InverseFaceColor_I {validatecolor} = [1, 0, 0];        Condition_I = @(x, y1, y2) y1 >= y2;        Line1Color_I {validatecolor} = [0, 0, 1];        Line2Color_I {validatecolor} = [1, 0, 0];        ContainsMappingToolbox matlab.lang.OnOffSwitchState = 'on';   end   methods       function obj = fillBetweenAreaCurve(varargin)           % Intialize list of arguments           args = varargin;           leadingArgs = cell(0);            if ~isempty(args) && numel(args) >= 3  && isnumeric(args{1}) ...                && isnumeric(args{2}) && isnumeric(args{3})                                   if numel(args) >= 3 && mod(numel(args), 2) == 1                   % fillBetweenAreaCurve(x, y1, y2)                   x = args{1};                   y1 = args{2};                   y2 = args{3};                   leadingArgs = [leadingArgs {'XData', x, 'Y1Data', y1 , 'Y2Data', y2 }];                   args = args(4:end);                               else                   % fillBetweenAreaCurve(x, y1, y2, color)                   x = args{1};                   y1 = args{2};                   y2 = args{3};                   color = args{4};                   leadingArgs = [leadingArgs {'XData', x, 'Y1Data', y1 , 'Y2Data', y2, 'FaceColor', color}];                   args = args(5:end);                end            else                warning('Invalid Input Arguments')            end                        % Combine positional arguments with name/value pairs            args = [leadingArgs args];            % Call superclass constructor method            obj@matlab.graphics.chartcontainer.ChartContainer(args{:});       end   end    methods(Access=protected)       function setup(obj)            ax = getAxes(obj);            hold(ax,'all')            obj.PatchObject = fill(ax, NaN, NaN, 'k');            obj.PatchObject.EdgeColor = 'none';            obj.PatchObject.Annotation.LegendInformation.IconDisplayStyle = 'off';            obj.InversePatchObject = fill(ax, NaN, NaN, 'k');            obj.InversePatchObject.Annotation.LegendInformation.IconDisplayStyle = 'off';            obj.InversePatchObject.EdgeColor = 'none';            obj.Line1Object = plot(ax, NaN, NaN);            obj.Line2Object = plot(ax, NaN, NaN);            % Setup colors of the plot to be the first 2 colors of the            % colororder            order = ax.ColorOrder;                        if obj.Line1ColorSetMode == "auto"                obj.Line1Color = order(1, :);            end            if obj.Line2ColorSetMode == "auto"                obj.Line2Color = order(2, :);            end            hold(ax,'off')            if ~any(strcmp('Mapping Toolbox', {ver().Name}))                 obj.ContainsMappingToolbox = 'off';                warning("Mapping Toolbox is not installed. " + ...                    "This may lead to degraded performance of the FillBetweenAreaCurve. " + ...                    "Install Mapping Toolbox for better performance")            end       end       function update(obj)            ax = getAxes(obj);            [obj.XData, obj.Y1Data, obj.Y2Data] = obj.Validator.performAllValidations( ...                obj.XData, obj.Y1Data, obj.Y2Data);            % Set Properties of Line 1            obj.Line1Object.XData = obj.XData;            obj.Line1Object.YData = obj.Y1Data;            obj.Line1Object.Color = obj.Line1Color;            obj.Line1Object.LineWidth = obj.Line1LineWidth;            obj.Line1Object.DisplayName = obj.Label1;            obj.Line1Object.LineStyle = obj.Line1LineStyle;                        % Set Properties of Line 2            obj.Line2Object.XData = obj.XData;            obj.Line2Object.YData = obj.Y2Data;            obj.Line2Object.Color = obj.Line2Color;            obj.Line2Object.LineWidth = obj.Line2LineWidth;            obj.Line2Object.DisplayName = obj.Label2;            obj.Line2Object.LineStyle = obj.Line2LineStyle;                        % If FaceColor/ InverseFaceColor has not be setup by user, use            % the corresponding line color            if obj.FaceColorSetMode == "auto"                obj.FaceColor_I = obj.Line1Color;            end            if obj.FaceColorSetMode == "auto"                obj.InverseFaceColor_I = obj.Line2Color;            end             % Set legend, title and axis labels of the graph            lgd = getLegend(obj);               title(ax, obj.Title);            xlabel(ax, obj.XLabel);            ylabel(ax, obj.YLabel);                        % To ensure accuracy of shading, we need to insert             % intersection points into the existing data.             if obj.ContainsMappingToolbox                [xi, yi] = polyxpoly(obj.XData, obj.Y1Data, obj.XData, obj.Y2Data);                XData_final = [obj.XData, xi.'];                Y1Data_final = [obj.Y1Data, yi.'];                Y2Data_final = [obj.Y2Data, yi.'];                         else                XData_final = obj.XData;                Y1Data_final = obj.Y1Data;                Y2Data_final = obj.Y2Data;            end            [XData_final, idx] = sort(XData_final);            Y1Data_final = Y1Data_final(idx);            Y2Data_final = Y2Data_final(idx);            % If the user provides a condition, we need to select all            % the values for which the condition evaluates to true.            % isInRange is a logical array where tells us which values            % to select for shading finally            isInRange = evaluateCondition(XData_final, Y1Data_final, Y2Data_final, obj.Condition);            % We then build a patch object to shade the curve using x, y1 and y2 values obtained above            buildPatchObjectForShadedAreaUsingLogicalArray(obj.PatchObject, isInRange, XData_final, Y1Data_final, Y2Data_final, ...                obj.FaceAlpha, obj.FaceColor, obj.OptimizePerformance);                        % If a user wants to shade the rest of the graph with a separate color,             % then we generate invert the isInRange logical array to pick all the             % values that do not satisfy condition. In this case, the            % isNotInRange logical array tells us which values to pick.             % We then further build a PatchObject using the new x , y1            % and y2 values            if obj.ShadeInverse                isNotInRange = generateInverseLogicalArray(isInRange);                buildPatchObjectForShadedAreaUsingLogicalArray(obj.InversePatchObject, isNotInRange, XData_final, Y1Data_final, Y2Data_final, ...                    obj.FaceAlpha, obj.InverseFaceColor, obj.OptimizePerformance);                                % If the user specifies a condition in there chart we need                % to turnsavefig on displaying area in the legends                if obj.ConditionSetMode == "manual"                     obj.PatchObject.Annotation.LegendInformation.IconDisplayStyle = 'on';                    obj.PatchObject.DisplayName = "Satisfies Condition";                    if obj.ShadeInverse                        obj.InversePatchObject.DisplayName = "Doesn't Satisfy Condition";                        obj.InversePatchObject.Annotation.LegendInformation.IconDisplayStyle = 'on';                    end                end            else                % If a user turns off ShadeInverse, color the inverse face                % as white and don't display it in the legend                obj.InversePatchObject.FaceColor = 'w';                obj.InversePatchObject.Annotation.LegendInformation.IconDisplayStyle = 'off';            end       end           end   methods(Access = {?tFillBetweenAreaCurve})       function ax = getTestAxes(obj)           ax = getAxes(obj);       end   end   methods       function set.FaceColor(obj, FaceColor)            obj.FaceColorSetMode = 'manual';            obj.FaceColor_I = validatecolor(FaceColor);       end       function faceColor = get.FaceColor(obj)            faceColor = obj.FaceColor_I;       end       function set.InverseFaceColor(obj, InverseFaceColor)            obj.InverseFaceColorSetMode = 'manual';            obj.InverseFaceColor_I = validatecolor(InverseFaceColor);       end       function inverseFaceColor = get.InverseFaceColor(obj)             inverseFaceColor = obj.InverseFaceColor_I;       end       function set.Condition(obj, condition)            obj.ConditionSetMode = 'manual';            obj.Condition_I = condition;       end       function condition = get.Condition(obj)            condition = obj.Condition_I;       end       function set.Line1Color(obj, LineColor)            obj.Line1ColorSetMode = 'manual';            obj.Line1Color_I = validatecolor(LineColor);       end       function line1Color = get.Line1Color(obj)            line1Color = obj.Line1Color_I;       end       function set.Line2Color(obj, LineColor)            obj.Line2ColorSetMode = 'manual';            obj.Line2Color_I = validatecolor(LineColor);       end           function line2Color = get.Line2Color(obj)            line2Color = obj.Line2Color_I;       end       function set.Line1LineWidth(obj, LineWidth)           obj.Line1LineWidth = LineWidth;       end       function set.Line2LineWidth(obj, LineWidth)           obj.Line2LineWidth = LineWidth;       end   endendfunction buildPatchObjectForShadedAreaUsingLogicalArray(patchObject, includeVals, XData, Y1Data, Y2Data, alpha, faceColor, optimizePerformance)    % Extract the X, Y1 and Y2 Data based on logical array -    % includeVals    filtered_XData = XData(includeVals);    filtered_Y1Data = Y1Data(includeVals);    filtered_Y2Data = Y2Data(includeVals);    patchObject.FaceAlpha = alpha;    patchObject.FaceColor = faceColor;         % Define the vertices polygon which will define our shaded area    poly_XData = [filtered_XData fliplr(filtered_XData)];    poly_YData = [filtered_Y1Data  fliplr(filtered_Y2Data)];    % Define Vertices and Faces for polygon that defines the shaded    % area    patchObject.Vertices = [poly_XData(:) poly_YData(:)];    patchObject.Faces = returnFaceList(includeVals, numel(poly_XData), optimizePerformance);    endfunction isInRange = evaluateCondition(XData, Y1Data, Y2Data, Condition)    % Use condition to filter out x, y1 and y2 values which do not    % satisfy the Condition function.    try        isInRange = Condition(XData, Y1Data, Y2Data);    catch ME       warning(ME.message + ". Invalid Function Supplied. Shading all regions")    end    filtered_XData = XData(isInRange);    filtered_Y1Data = Y1Data(isInRange);    filtered_Y2Data = Y2Data(isInRange);           end% While shading there can be discontinuous regions in our shaded area. % These discontiuous regions each consitute a seperate Face in our% PatchObject% Given the number of vertices and boolean array describing% which x-values are included in the shaded area the function % returns a 2-d array where each row specifies how vertices will be% connectedfunction faceList = returnFaceList(true_vals, nVertices, optimizePerformance)    contLengthList = [];    currentLength = 0;    % Find continuous regions in the shaded areas     for i = 1 : numel(true_vals)        if true_vals(i)            currentLength = currentLength + 1;        elseif currentLength > 0            contLengthList = [contLengthList; currentLength];            currentLength = 0;        end    end    if currentLength > 0        contLengthList = [contLengthList; currentLength];    end    faceList = [];    startVertex = 1;    endVertex = nVertices;    maxCurrentLength = 2 *  max(contLengthList) + 1;    % Create a single face with continuous regions     for i = 1: numel(contLengthList)        contLength = contLengthList(i);        % If OptimizePerformance is turned off, For each face we just        % calculate which vertices are part of a face and pass it to patch        % Internally, Patch will triangulate the polygon and calculate        % vertices of the triangle        if ~optimizePerformance            currFaceList = [startVertex: startVertex + contLength - 1, endVertex - contLength + 1: endVertex, startVertex];            currFaceList = [currFaceList, NaN(1, maxCurrentLength - numel(currFaceList))];            faceList = [faceList; currFaceList];                 % If OptimizePerformance is turned on, For each face we calculate         % vertices of triangles that will form the polygon. Each face will         % have 3 vertices, Each vertices will be part of 2 face.         else                 topLineSegmentIdxs = startVertex: startVertex + contLength - 1;            bottomLineSegmentIdxs = endVertex: -1: endVertex - contLength + 1;            topLineSegmentPtr = 1; bottomLineSegmentPtr = 1;            while topLineSegmentPtr < numel(topLineSegmentIdxs) && bottomLineSegmentPtr < numel(bottomLineSegmentIdxs)                faceList = [faceList; topLineSegmentIdxs(topLineSegmentPtr), topLineSegmentIdxs(topLineSegmentPtr + 1), bottomLineSegmentIdxs(bottomLineSegmentPtr)];                faceList = [faceList; bottomLineSegmentIdxs(bottomLineSegmentPtr), bottomLineSegmentIdxs(bottomLineSegmentPtr + 1), topLineSegmentIdxs(topLineSegmentPtr + 1)];                topLineSegmentPtr = topLineSegmentPtr + 1;                bottomLineSegmentPtr = bottomLineSegmentPtr + 1;            end        end        startVertex = startVertex + contLength;        endVertex = endVertex - contLength;    endendfunction isNotInRange = generateInverseLogicalArray(isInRange)      isNotInRange = ~isInRange;      for i = 1:numel(isInRange)          if i < numel(isInRange) && isInRange(i) && ~isInRange(i + 1)              isNotInRange(i) = true;          elseif i > 1 && isInRange(i) && ~isInRange(i - 1)              isNotInRange(i) = true;          end      endend
classdef hTestFillAreaBetweenCurve < fillBetweenAreaCurve    methods        function callSetup(obj)            setup(obj)        end                function callUpdate(obj)            update(obj)        end            endend
classdef hTestFillAreaBetweenCurve < fillBetweenAreaCurve    methods        function callSetup(obj)            setup(obj)        end                function callUpdate(obj)            update(obj)        end            endend
classdef tFillBetweenAreaCurve < matlab.unittest.TestCase    properties        TestFigure    end    properties(TestParameter)        testSyntaxesData = createTestSyntaxesData;        testErrorData = createTestErrorData;        testInterpolateData = createTestInterpolateData;        testFigureOrderData = createTestFigureOrderData;        testEmptyData = createTestEmptyData;    end    methods(TestClassSetup)        function createFigure(testCase)            testCase.TestFigure = figure;            testCase.addTeardown(@() delete(testCase.TestFigure));        end    end    methods(Test)        function testSyntaxes(testCase, testSyntaxesData)             args = testSyntaxesData.Args;           h = hTestFillAreaBetweenCurve(args{:});           h.callUpdate();           expectedXData = testSyntaxesData.XData;           expectedY1Data = testSyntaxesData.Y1Data;           expectedY2Data = testSyntaxesData.Y2Data;           expectedFaceColorData = testSyntaxesData.FaceColor;           testCase.verifyEqual(h.XData, expectedXData);           testCase.verifyEqual(h.Y1Data, expectedY1Data);           testCase.verifyEqual(h.Y2Data, expectedY2Data);           testCase.verifyEqual(h.FaceColor, expectedFaceColorData);        end        function testEmptyDataDoesntBreakChart(testCase, testEmptyData)            args = testEmptyData.Args;            h = hTestFillAreaBetweenCurve(args{:});            h.callUpdate();                      h.XData = [];            h.Y1Data = [];            h.Y2Data = [];            h.callUpdate();           end        function testFigureOrder(testCase, testFigureOrderData)            args = testFigureOrderData.Args;            h = hTestFillAreaBetweenCurve(args{:});            figObjects = h.getTestAxes().Children;            testCase.verifyEqual(numel(figObjects), 4);            testCase.verifyEqual(class(figObjects(1)), 'matlab.graphics.chart.primitive.Line');            testCase.verifyEqual(class(figObjects(2)), 'matlab.graphics.chart.primitive.Line');            testCase.verifyEqual(class(figObjects(3)), 'matlab.graphics.primitive.Patch');            testCase.verifyEqual(class(figObjects(4)), 'matlab.graphics.primitive.Patch');        end        function testErrors(testCase, testErrorData)            args = testErrorData.Args;            errorIdentifier = testErrorData.id;            errorMsg = testErrorData.errorMsg;            %             % h = hTestFillAreaBetweenCurve(args{:});            testCase.verifyError(@()hTestFillAreaBetweenCurve(args{:}), errorIdentifier, errorMsg);        end    endendfunction testSyntaxesData = createTestSyntaxesData    XData = linspace(0, 4 * pi, 100);    Y1Data = sin(XData);    Y2Data = cos(XData);    faceColor = [0.4 0.2 0.3];    args1 = {XData Y1Data Y2Data};    args2 = {XData Y1Data Y2Data faceColor};        testSyntaxesData = struct( ...        'SetXY1Y2DataSyntax', struct('Args', {args1}, 'XData', {XData}, ...        'Y1Data', Y1Data, 'Y2Data', Y2Data, 'FaceColor', 'g') , ...        'SetXY1Y2ColorDataSyntax', struct('Args', {args2}, 'XData', {XData}, ...        'Y1Data', Y1Data, 'Y2Data', Y2Data, 'FaceColor', faceColor));    endfunction testInterpolateData = createTestInterpolateData    XData = linspace(0, 4 * pi, 100);    Y1Data = sin(XData);    Y2Data = cos(XData);    [xi, yi] = polyxpoly(XData, Y1Data, XData, Y2Data);    inter_XData = [XData, xi.'];    inter_Y1Data = [Y1Data, yi.'];    inter_Y2Data = [Y2Data, yi.'];    [inter_XData, idx] = sort(inter_XData);    inter_Y1Data = inter_Y1Data(idx);    inter_Y2Data = inter_Y2Data(idx);    args = {XData Y1Data Y2Data "Interpolate" true};    testInterpolateData = struct( ...        'SetInterpolateTrue', struct('Args', {args}, 'XData', inter_XData, ...        'Y1Data', inter_Y1Data, 'Y2Data', inter_Y2Data));endfunction testErrorData = createTestErrorData        XData = 1:10;        Case1_Y1Data = 1:11;        Case1_Y2Data = 1:10;        Case1_args = {XData Case1_Y1Data Case1_Y2Data};        Case1_Y1Data = 1:10;        Case2_Y2Data = 1:11;        Case2_args = {XData Case1_Y1Data Case2_Y2Data};        testErrorData = struct( ...            'XNotEqualToY1', struct('Args', {Case1_args}, 'id', 'invalid1:InputsAreInvalid', 'errorMsg', 'Length of x is not equal to length of y1'), ...            'XNotEqualToY2', struct('Args', {Case2_args}, 'id', 'invalid2:InputsAreInvalid', 'errorMsg', 'Length of x is not equal to length of y2'));endfunction testFigureOrderData = createTestFigureOrderData    XData = linspace(0, 4 * pi, 100);    Y1Data = sin(XData);    Y2Data = cos(XData);    args = {XData Y1Data Y2Data};    testFigureOrderData = struct( ...        'TestFigureOrder', struct('Args', {args}));endfunction testEmptyData = createTestEmptyData    Empty_XData = [];    Empty_Y1Data = [];    Empty_Y2Data = [];    emptyargs = {Empty_XData Empty_Y1Data Empty_Y2Data};    testEmptyData = struct( ...        'SetXY1Y2Empty', struct('Args', {emptyargs}, 'XData', {Empty_XData}, ...        'Y1Data', {Empty_Y1Data}, 'Y2Data', {Empty_Y2Data}, 'FaceColor', 'g') ...    );end

⛄ 运行结果

⛄ 参考文献

⛳️ 代码获取关注我

❤️部分理论引用网络文献,若有侵权联系博主删除
❤️ 关注我领取海量matlab电子书和数学建模资料

🍅 仿真咨询

1 各类智能优化算法改进及应用
生产调度、经济调度、装配线调度、充电优化、车间调度、发车优化、水库调度、三维装箱、物流选址、货位优化、公交排班优化、充电桩布局优化、车间布局优化、集装箱船配载优化、水泵组合优化、解医疗资源分配优化、设施布局优化、可视域基站和无人机选址优化
2 机器学习和深度学习方面
卷积神经网络(CNN)、LSTM、支持向量机(SVM)、最小二乘支持向量机(LSSVM)、极限学习机(ELM)、核极限学习机(KELM)、BP、RBF、宽度学习、DBN、RF、RBF、DELM、XGBOOST、TCN实现风电预测、光伏预测、电池寿命预测、辐射源识别、交通流预测、负荷预测、股价预测、PM2.5浓度预测、电池健康状态预测、水体光学参数反演、NLOS信号识别、地铁停车精准预测、变压器故障诊断
2.图像处理方面
图像识别、图像分割、图像检测、图像隐藏、图像配准、图像拼接、图像融合、图像增强、图像压缩感知
3 路径规划方面
旅行商问题(TSP)、车辆路径问题(VRP、MVRP、CVRP、VRPTW等)、无人机三维路径规划、无人机协同、无人机编队、机器人路径规划、栅格地图路径规划、多式联运运输问题、车辆协同无人机路径规划、天线线性阵列分布优化、车间布局优化
4 无人机应用方面
无人机路径规划、无人机控制、无人机编队、无人机协同、无人机任务分配
5 无线传感器定位及布局方面
传感器部署优化、通信协议优化、路由优化、目标定位优化、Dv-Hop定位优化、Leach协议优化、WSN覆盖优化、组播优化、RSSI定位优化
6 信号处理方面
信号识别、信号加密、信号去噪、信号增强、雷达信号处理、信号水印嵌入提取、肌电信号、脑电信号、信号配时优化
7 电力系统方面
微电网优化、无功优化、配电网重构、储能配置
8 元胞自动机方面
交通流 人群疏散 病毒扩散 晶体生长
9 雷达方面
卡尔曼滤波跟踪、航迹关联、航迹融合

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值