i hope i will get good feed back.I have this code to stimulate absorption loss but an alert message displayed.Can you help me please

1 view (last 30 days)
%atténuation
clc;
f=450;
d=[0 5 10 15 20 25 30 35];
for i=1:length(d)
alfa(i) = 20*log10((4*3.14*d(i))/4);
end;
figure(1)
plot( d,alfa,'r->');
title('Caracteristiques de l atténuation en fonction de la distance','fontsize',12,'fontweight','b');
xlabel('Distance(km), d (km)','fontsize',12,'fontweight','b');
ylabel('Attenuation(dB)','fontsize',12,'fontweight','b');
grid on;
____________________
??? Error using ==> plot Vectors must be the same lengths.
Error in ==> attenuationalfa at 11 plot( alfa,d,'r->');

Accepted Answer

the cyclist
the cyclist on 1 Jun 2014
That code runs just fine for me.
Try this:
clear d alfa
and run it again.

More Answers (1)

Geoff Hayes
Geoff Hayes on 1 Jun 2014
Edited: Geoff Hayes on 1 Jun 2014
I was able to run through the above code and it passed without the error that you observed. What the message means is that the two input (to plot) vectors, alfa and d, are not of the same dimension. d is obviously a 1x8 vector, and alfa should be the same - after all, the code is iterating over the length of d and initializing alfa according to your equation. And when I step through the code, at the line where the plot command is invoked, both vectors are of the same dimension.
What I did notice was that the first element of alfa is -Inf. This is explainable because the first element of d is zero. I wonder if somehow this is the problem, and the -Inf is being removed from alfa making this vector a 1x7 rather than the 1x8. Try running through the above code again but this time, change the d vector to
d =[5 10 15 20 25 30 35];
My version of MATLAB (R2014a) knows not to plot the first pair of values because of the invalid -Inf. Which version are you using?

Categories

Find more on Specifying Target for Graphics Output in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!