Find max and min every n elements in a matrix, then plot with error bar together with mean value

8 ビュー (過去 30 日間)
Hello i am reading a matrix with 2 columns. The first columns has a radius and the second column stores a value. there are n * m rows, where n is the number of groups and m is the number of elements in each group.
Example Matrix
A(:,1) = 0.01:0.01:1.1 % radius
A(:,2) = rand(110,1) % value
Now i want to find the average every m elements, in this case lets say 10 groups of 11 elements
B(:,1) = accumarray(ceil((1:numel(A(:,1)))/11)',A(:,1),[],@mean)% average of radii
B(:,2) = accumarray(ceil((1:numel(A(:,2)))/11)',A(:,2),[],@mean)% average of value
Now my 1. question: How can i efficiently find the max and min of each group?
Also later i plot array B like so:
plot(fig,B(:,1),B(:,2),'k-o')
and my 2. question: How can i add the min and max values as an error bar to the plot above? i.e.
|----o----|
Thanks a lot

採用された回答

Adam Danz
Adam Danz 2022 年 1 月 13 日
編集済み: Adam Danz 2022 年 1 月 13 日
How can i efficiently find the max and min of each group?
Hint: use the same accumarray function except replace mean with max or min.
How can i add the min and max values as an error bar
Use the errorbar function. errorbar(x,y,neg,pos) where neg and pos are the distance of the min,max from the mean. Give it a shot and if you get stuck, show us what you've got and we can help more.
  3 件のコメント
Adam Danz
Adam Danz 2022 年 1 月 13 日
編集済み: Adam Danz 2022 年 1 月 13 日
The errorbars shouldn't look like a filled surface. Could you show me an example or provide data and code that reproduces what you're seeing?
To answer your question, set linestyle to none to remove the line that connects multiple error bars, if that's what you want to do.
The undocumented bar property has a visible property that can be set to off which will remove the bars that connects the caps. But that makes the caps difficult to see so you can extend their length by increasing capsize and increase their line width by increasing linewidth.
Demo
eb = errorbar(1:3, [0.2, 0.5, 0.3], ...
'LineStyle', 'none', ...
'CapSize', 15, ...
'LineWidth', 2);
eb.Bar.Visible = 'off';
Ángel Brito Gadeschi
Ángel Brito Gadeschi 2022 年 1 月 14 日
編集済み: Ángel Brito Gadeschi 2022 年 1 月 14 日
Thanks a lot for the helpful answer!, this solved it.
It looked like a filled surface because i have way too many points (or my plot is too small, but it already covers the entire screen)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

製品


リリース

R2017a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by