필터 지우기
필터 지우기

How to plot a chart(e.g bar chart) given a dublicate x values?

조회 수: 2 (최근 30일)
yashvin
yashvin 2015년 7월 7일
댓글: yashvin 2015년 7월 9일
Hi I have 2 arrays
time_duration=[2 4 3 6 7 3 7]
Altitude=[20 30 40 50 60 60 50]
Sometimes, for the same time duration, I have 2 Altitude values. For example for time_duration= 3, I have Altitude = 40 ad 60. I want to plot it so that on the xaxis time_duration=3, I can have altitude 100 ie (40+60) on the yaxis.
I tried with barchart but it is not allowing it as of duplicate values.
bar(time_duration,Altitude)
XData cannot contain duplicate values.
Any suggestions?

채택된 답변

Andrei Bobrov
Andrei Bobrov 2015년 7월 7일
편집: Andrei Bobrov 2015년 7월 7일
[a1,~,c1] = unique(time_duration);
A1 = accumarray(c1(:),Altitude(:));
bar(a1(:),A1(:));
  댓글 수: 1
yashvin
yashvin 2015년 7월 9일
@Andrei
Anyway I can achieve this without using in-built function?
Thanks

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2015년 7월 7일
time_duration=[2 4 3 6 7 3 7]
Altitude=[20 30 40 50 60 60 50]
[unique_time_duration,jj,kk]=unique(time_duration)
new_Altitude=accumarray(kk,Altitude)
out=[unique_time_duration' new_Altitude]
  댓글 수: 1
yashvin
yashvin 2015년 7월 9일
@ Azzi
Anyway I can achieve this without using in-built function?
Thanks

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Bar Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by