matlab如何让plot更平滑,如何在MATLAB中平滑繪圖?

本文介绍了在MATLAB中使plot更平滑的几种方法,包括加权平均、使用smooth函数、Savitzky-Golay过滤以及移动平均。讨论了如何选择合适的平滑程度,以及针对异常值的处理建议。
摘要由CSDN通过智能技术生成

I have some 9000 points that are plotted on a graph:

我在圖上畫了9000點

(完整的決議)

78018f6ea5cd7ee5803b93fad89e9ee6.jpe

Actually, the plot is not as smooth as I wanted it to be. Is there some way I can smoothen the graph to a required degree?

實際上,情節並不像我想象的那么順利。有沒有什么方法可以讓圖形達到要求的程度?

Or some form of thresholding so that I can selectively smoothen out the parts that is too bumpy?

或者某種形式的閾值,這樣我可以有選擇地撫平那些太顛簸的部分?

I am not sure but can fast-fourier-transform help?

我不確定,但是快速傅里葉變換能有幫助嗎?

5 个解决方案

#1

17

A simple (ad hoc) way is to just take a weighted average (tunable by alpha) at each point with its neighbors:

一個簡單(特別)的方法是,在每個點與它的左鄰右取一個加權平均(可調):

data(2:n-1) = alpha*data(2:n-1) + (1-alpha)*0.5*(da

以下是一个例子,展示如何使用单选按钮组在MATLAB App Designer绘制三幅不同的像: 1. 在App Designer创建一个新的Blank App 2. 在Design View添加一个Axes组件和一个Button Group组件 3. 在Axes绘制一个默认的像(例如,使用plot命令绘制一个sin函数) 4. 在Button Group添加三个单选按钮,并设置它们的String属性为“Plot 1”,“Plot 2”和“Plot 3” 5. 在Button Group添加一个SelectionChangedFcn回调函数,用于检测单选按钮的改,并在Axes绘制相应的像 以下是示例代码: ```matlab classdef app1 < matlab.apps.AppBase % Properties that correspond to app components properties (Access = public) UIFigure matlab.ui.Figure Axes matlab.ui.control.UIAxes ButtonGroup matlab.ui.container.ButtonGroup Plot1Button matlab.ui.control.RadioButton Plot2Button matlab.ui.control.RadioButton Plot3Button matlab.ui.control.RadioButton end % Callbacks that handle component events methods (Access = private) % Button group selection changed function function ButtonGroupSelectionChanged(app, event) selectedButton = app.ButtonGroup.SelectedObject; if selectedButton == app.Plot1Button % Plot the first graph x = linspace(0, 2*pi); y = sin(x); plot(app.Axes, x, y); elseif selectedButton == app.Plot2Button % Plot the second graph x = linspace(-5, 5); y = x.^2; plot(app.Axes, x, y); elseif selectedButton == app.Plot3Button % Plot the third graph x = -5:0.1:5; y = exp(-x.^2); plot(app.Axes, x, y); end end end % App initialization and construction methods (Access = private) % Create UIFigure and components function createComponents(app) % Create UIFigure app.UIFigure = uifigure; app.UIFigure.Position = [100 100 640 480]; app.UIFigure.Name = 'UI Figure'; app.UIFigure.Resize = 'off'; % Create Axes app.Axes = uiaxes(app.UIFigure); title(app.Axes, 'Plot 1'); xlabel(app.Axes, 'X'); ylabel(app.Axes, 'Y'); app.Axes.Position = [150 100 300 300]; % Create ButtonGroup app.ButtonGroup = uibuttongroup(app.UIFigure); app.ButtonGroup.SelectionChangedFcn = createCallbackFcn(app, @ButtonGroupSelectionChanged, true); app.ButtonGroup.Title = 'Select Plot'; app.ButtonGroup.Position = [50 100 70 127]; % Create Plot1Button app.Plot1Button = uiradiobutton(app.ButtonGroup); app.Plot1Button.Text = 'Plot 1'; app.Plot1Button.Position = [11 87 56 22]; app.Plot1Button.Value = true; % Create Plot2Button app.Plot2Button = uiradiobutton(app.ButtonGroup); app.Plot2Button.Text = 'Plot 2'; app.Plot2Button.Position = [11 64 56 22]; % Create Plot3Button app.Plot3Button = uiradiobutton(app.ButtonGroup); app.Plot3Button.Text = 'Plot 3'; app.Plot3Button.Position = [11 41 56 22]; end end % App creation and deletion methods (Access = public) % Construct app function app = app1 % Create UIFigure and components createComponents(app) % Register the app with App Designer registerApp(app, app.UIFigure) % Execute the startup function runStartupFcn(app, @startupFcn) if nargout == 0 clear app end end % Code that executes before app deletion function delete(app) % Delete UIFigure when app is deleted delete(app.UIFigure) end end end ``` 在这里,我们创建了一个名为app1的类,并在其定义了三个单选按钮和一个Axes。在单选按钮的SelectionChangedFcn回调函数,我们使用plot命令绘制相应的形。示例代码绘制的三幅像分别为sin函数、二次函数和高斯函数。 将此代码复制并运行,您应该能够在应用程序选择三个不同的像,并在Axes绘制它们。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值