从matlab绘图中获取平均值?

发布于 2024-08-27 03:44:49 字数 84 浏览 9 评论 0原文

当我有图表时,我有一个简单的图,其中包含大量数据点。有没有一种方法可以让我简单地单击所有这些点并让 matlab 给出它们的平均值?

谢谢

I have a simple plot which feature a lot of data points, when i have have graph. Is there a way that i can simple click on all these point and allow matlab to give me a average value of them?

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

百思不得你姐 2024-09-03 03:44:49

另一种选择是使用数据刷

单击图形工具栏上的画笔图标并进行选择。然后在菜单中选择“工具”-“刷子”-“创建新变量”。您可以保留默认变量名称 ans。该变量将包含所有选定点的 X 和 Y 坐标。然后只需运行 mean(ans(:,2)) 即可获得 Ys 的平均值。

Another option is to use data brush.

Click brush icon on the figure toolbar and make a selection. Then select in menu Tools-Brushing-Create new variable. You can leave default variable name ans. This variable will contain X and Y coordinates of all selected points. Then just run mean(ans(:,2)) to get average of Ys.

执妄 2024-09-03 03:44:49

如果您不想以编程方式执行此操作,最简单的方法是使用数据刷和统计数据。

我使用plot(rand(1,200)) 来生成数据。绘制完成后,转到“工具”>“数据统计。 Y-mean 就是您正在寻找的。

替代文本 http://www.thinkextensely.com/misc/stackoverflow/images/ matlab2.png”

要获取特定数据集的平均值,请选择所需的数据,然后在菜单中转到“工具”>“ 。刷牙>创建新变量。 。 ..这将创建一个包含装箱数据的变量。要获取平均值,请执行 mean(ans)。向量中的第二个值是 Y 均值。
替代文本 http://www.thinkextensely.com/misc/stackoverflow/images/ matlab1.png

The easiest way if you don't want to do it programmatically would be to use the data brush and statistics.

I used plot(rand(1,200)) to generate my data. After it has plotted go to Tools > Data Statistics. Y-mean is what you are looking for.

alt text http://www.thinkextensively.com/misc/stackoverflow/images/matlab2.png

To get the mean of a specific set of data, select the data you want, then in the menu go to Tools > Brushing > Create New Variable . . .. This creates a variable containing the boxed data. To get the mean do mean(ans). The second value in the vector is the Y-mean.
alt text http://www.thinkextensively.com/misc/stackoverflow/images/matlab1.png

迷乱花海 2024-09-03 03:44:49

不太清楚您想要计算的值的平均值。我认为,它是 y 坐标。

我将使用 RBBOX 函数来选择绘图上的点集。

试试这个代码:

% sample data
data = rand(1,100);
datax = 1:numel(data);

% draw simple plot
plot(data,'.')

% select the points with mouse and get coordinates
k = waitforbuttonpress;
point1 = get(gca,'CurrentPoint');    % button down detected
finalRect = rbbox;                   % return figure units
point2 = get(gca,'CurrentPoint');    % button up detected
point1 = point1(1,1:2);              % extract x and y
point2 = point2(1,1:2);
pmin = min(point1,point2);
pmax = max(point1,point2);

% find the data selected and get average of y values
idx = data >= pmin(2) & data <= pmax(2) & datax >=pmin(1) & datax <= pmax(1);
dataAverage = mean(data(idx));

我必须声明这个代码的大部分来自 rbbox 文档。

Not very clear average of what values you wanted to calculate. I assume, it's y-coordinates.

I would use RBBOX function to select set of points on the plot.

Try this code:

% sample data
data = rand(1,100);
datax = 1:numel(data);

% draw simple plot
plot(data,'.')

% select the points with mouse and get coordinates
k = waitforbuttonpress;
point1 = get(gca,'CurrentPoint');    % button down detected
finalRect = rbbox;                   % return figure units
point2 = get(gca,'CurrentPoint');    % button up detected
point1 = point1(1,1:2);              % extract x and y
point2 = point2(1,1:2);
pmin = min(point1,point2);
pmax = max(point1,point2);

% find the data selected and get average of y values
idx = data >= pmin(2) & data <= pmax(2) & datax >=pmin(1) & datax <= pmax(1);
dataAverage = mean(data(idx));

I have to claim large portion of this code is from rbbox documentation.

鸵鸟症 2024-09-03 03:44:49

我猜您想根据已绘制的数据绘制平均值(或至少计算它)。

使用 plotAverage 来自 Matlab 文件交换,您可以轻松完成。

%# plot some data
figure
plot(randn(100,5))

%# add the average line at every 5th point
[plotHandles, average] = plotAverage([],5:5:95);

%# and you have a line on the plot, and its handles and data in the workspace.

I guess that you want to plot an average (or at least calculate it) from already plotted data.

With plotAverage from the Matlab File Exchange, you can do it quite easily.

%# plot some data
figure
plot(randn(100,5))

%# add the average line at every 5th point
[plotHandles, average] = plotAverage([],5:5:95);

%# and you have a line on the plot, and its handles and data in the workspace.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文