How to add text over my bar chart?

조회 수: 1 (최근 30일)
TRISHITA BANERJEE
TRISHITA BANERJEE 2018년 7월 25일
댓글: Aarti Dwivedi 2018년 7월 26일
I need to add text corresponding to the y axis in my current code..what extra should I add there?
fs = 48000;
L1 = 0.1 * fs;
L2 = 0.01 * fs;
K = 5;
w1 = 50 / fs;
w2 = 20e3 / fs;
c = log(w2/w1);
T = 1.5 * fs;
N = 5;
T_i = zeros(1,N);
ti_K = zeros(1,N);
T_MESM = zeros(1,N);
for n = 1:N
T_i(n) = ((n-1)*L1 + L2) * c/log(2); % sweep length for interleaving n sweeps
if T_i(n) < T
T_i(n) = T;
end
ti_K(n) = T_i(n)/c * log(K); % distance of IR to kth HIR
T_MESM(n) = T_i(n) + ti_K(n)*(N/n-1) + N*L1;
end
t_MESM = T_MESM/fs;
t_i = T_i / fs;
% optimal n
n_opt = ceil( (T*log(2))/(c*L1) + (L1+L2)/L1 );
figure;
for k = 1:N
bar(k,T_MESM(k)/fs);
hold on;
end
hold off; %grid on;
figure;
for k = 1:N
bar(k,T_i(k)/fs);
hold on;
end
hold off; %grid on;
rel_T = T_i(n_opt) / T;
rel_n = (1 + log(K)/c*(N/(n_opt-1)-1)) / (1 + log(K)/c*(N/n_opt-1));
  댓글 수: 2
TRISHITA BANERJEE
TRISHITA BANERJEE 2018년 7월 25일
Found a solution to my answer:
clear all close all
fs = 48000; % fstart = 55;%55; % fend = fs/2;%24100; %Possible values 20k and 24k % A = 0.04;%0.025; for 0.6m%0.6;%for 1m distance%0.7;%for1.5m % % L1 = 9350; % for -70 db % L2 = 2250; % W1=2*pi*f_start/fs; % W2=2*pi*f_end/fs; L1 = 0.1 * fs; L2 = 0.01 * fs; K = 5; w1 = 50 / fs; w2 = 20e3 / fs; c = log(w2/w1); T = 1.5 * fs; N = 5;
T_i = zeros(1,N); ti_K = zeros(1,N); T_MESM = zeros(1,N);
for n = 1:N T_i(n) = ((n-1)*L1 + L2) * c/log(2); % sweep length for interleaving n sweeps if T_i(n) < T T_i(n) = T; end ti_K(n) = T_i(n)/c * log(K); % distance of IR to kth HIR
T_MESM(n) = T_i(n) + ti_K(n)*(N/n-1) + N*L1;
end
t_MESM = T_MESM/fs;
t_i = T_i / fs;
% optimal n n_opt = ceil( (T*log(2))/(c*L1) + (L1+L2)/L1 );
figure; for k = 1:N y=T_MESM(k)/fs; bar(k,y); for i=1:numel(y) text(k(i),y(i),num2str(y(i),'%0.2f'),... 'HorizontalAlignment','center',... 'VerticalAlignment','bottom') end hold on; end hold off; %grid on;
figure; for k = 1:N y=T_i(k)/fs; bar(k,T_i(k)/fs); for i=1:numel(y) text(k(i),y(i),num2str(y(i),'%0.2f'),... 'HorizontalAlignment','center',... 'VerticalAlignment','bottom') end hold on; end hold off; %grid on;
% n = 4; % %%%%% Equation (14) from Paper %%%%% % b0 = L1 * (c-log(K)); % b1 = (L2-L1)/(c-log(K)) + N*L1*log(2*K); % b2 = (L2+L1) * N * log(K); % % T_paper = 1/log(2) * (b0*n + b1 + b2/n); % T_paper = T_paper / fs % % %%%%% My Equation %%%%% % a0 = L1 * (c-log(K)); % a1 = (L2-L1)*(c-log(K)) + N*L1*log(2*K); % a2 = N * log(K) * (L2-L1); % % T_paddy = 1/log(2) * (a0*n + a1 + a2/n); % T_paddy = T_paddy / fs
rel_T = T_i(n_opt) / T; rel_n = (1 + log(K)/c*(N/(n_opt-1)-1)) / (1 + log(K)/c*(N/n_opt-1));
Aarti Dwivedi
Aarti Dwivedi 2018년 7월 26일
Please put your solution as an answer.

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

답변 (0개)

카테고리

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