Problems trying to use bar

3 Ansichten (letzte 30 Tage)
Borja Zamarreño
Borja Zamarreño am 10 Jun. 2020
Kommentiert: Borja Zamarreño am 10 Jun. 2020
Hello im suffering some problem while trying to plot my data into bars. i have an array(7000x2)
data=xlsread('data.xlsx');
a= sortrows(data);
a(a(:,2) == 0, :) = [] ;
[U1,~,G1] = uniquetol(a(:,1));
S1 = accumarray(G1(:),a(:,2));
M1 = [U1,S1];
figure
plot(M1(:,1),M1(:,2))
ylabel('data')
xlabel('alpha')
What i want to obtain is the same figure but instead of lines with bars. I tried using bar instead of plot but nothing is showing.
Thank u in advance.
  2 Kommentare
Rik
Rik am 10 Jun. 2020
Those bars are just too thin for you to see:
bar(M1(:,1),M1(:,2)),hold on
plot(M1(:,1),M1(:,2),'.b')
xlim([0 0.01])
Borja Zamarreño
Borja Zamarreño am 10 Jun. 2020
Thank for your response, there is no option to wide those bars then?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Rik
Rik am 10 Jun. 2020
You can use the function below to create fake bars by using plot. This function accepts (nearly) all input arguments that plot accepts.
data=xlsread('data.xlsx');
a= sortrows(data);
a(a(:,2) == 0, :) = [] ;
[U1,~,G1] = uniquetol(a(:,1));
S1 = accumarray(G1(:),a(:,2));
M1 = [U1,S1];
figure(1),clf(1)
subplot(1,2,1)
bar(M1(:,1),M1(:,2)),hold on
plot(M1(:,1),M1(:,2),'.b')
xlim([0 0.01])
title('zoomed in')
subplot(1,2,2)
linebar(M1(:,1),M1(:,2),'b')
title('fake bars with lines')
function linebar(x,y,varargin)
x_=x(:);
sz=size(x_);
x_=[NaN(sz) x_ x_]';
y_=[NaN(sz) zeros(sz) y(:)]';
plot(x_,y_,varargin{:})
end
You can vastly increase the perfomance if you make it a continuous line by returning to y=0 instead of using NaN, but that is up to you.
  1 Kommentar
Borja Zamarreño
Borja Zamarreño am 10 Jun. 2020
Thank u very much for your help i will try it.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Data Distribution Plots finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by