12 views (last 30 days)

Show older comments

Hello,

I would like to plot a graph which shows the results of a for loop that derived a matrix Y(20,1001). I would like all the results of the iterations of Y to be plotted as one continuous line graph instead of all the iterations separately. However my code plots a graph with several lines of different colour, which I'm assuming its plotting the result of each iteration separately in the same graph. Hope I'm explaining my self clearly. My loop is underneath. Any tips would be appreciated. Thanks.

f=0:1000;

w=2*pi*f;

F=1;

%plate dimensions ad exciter location

Lx=0.286;

Lz=0.198;

x0=0.16;

z0=0.083;

%Plate data - Fibre board

h=3.25e-3 ; %thickness

E=1.4e9 ; %Young?s modulus

M=265*h; %Mass per unit area

mu=0.3; %Poisson?s ratio

eta=4e-2; %Damping Factor

p=265;

D=(E*(h^3))/(12*(1-mu)); %flexural rigidity

% calculate the eigenfrequencies and modes

i = 0;

for m = 1:5;

for n = 1:5;

if i<=19

i = i + 1;

wmn(i)=(sqrt(D/(p*h)))*((((n*pi)/Lx)^2)+(((m*pi)/Lz)^2)); %modal

angular frequency

mode(i,:) = [m n];

end

end

end

%sort the eigenfrequencies and the mode numbers

[wmn, I] = sort(wmn); wmn = wmn';

modesort(1:i,:)=mode(I,:);

T = [wmn, modesort];

i=0;

for q = 1:length(T(:,1))

i=i+1;

Y(i,:)=((4./(Lx.*Lz)).*(1./p))...

.*(((sin((T(q,2).*pi.*x0)./Lx).*sin((T(q,3).*pi.*z0)./Lz))...

.*(sin((T(q,2).*pi.*x0)./Lx).*sin((T(q,3).*pi.*z0)./Lz)))...

./((-w.^2)+(((T(q,1)).^2)*(1+(1j*(2*eta/(T(q,1))))))));

figure(1)

plot(f,20*log10(abs(Y)).')

end

Jing
on 17 May 2013

Hi Catarina, Y is a 20*1001 matrix! When you use plot, there'll be 20 lines for each row. If Y should be one line, you should not make it a 20*2001 matrix at first, or reshape it into a vector:

Y=Y';

Y=Y(:);

And you don't need to put PLOT into for loop if you don't want the plot of each iteration.

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

Start Hunting!