How to plot results from for loop as one line graph instead of separate results of each iteration?

3 ビュー (過去 30 日間)
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
  2 件のコメント
Jing
Jing 2013 年 5 月 16 日
There're many variables undefined in your code. And if the last PLOT function is outside of your for loop, it won't be the result of each iteration.
catarina
catarina 2013 年 5 月 16 日
Hi Jing, I've added all the necessary variables now. Cant figure this out.

サインインしてコメントする。

回答 (3 件)

Walter Roberson
Walter Roberson 2013 年 5 月 16 日
plot(f,(abs(Y)).')
  1 件のコメント
catarina
catarina 2013 年 5 月 16 日
Hi Walter, I changed as you suggested but get the same results. I added the whole code to my question above.

サインインしてコメントする。


catarina
catarina 2013 年 5 月 16 日
Hi Walter, I changed as you suggested but get the same results. I added the whole code to my question above.

Jing
Jing 2013 年 5 月 17 日
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.

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by