Clear Filters
Clear Filters

How to make a plot using two variables

2 views (last 30 days)
If you run this code you'll get graph shows natural frequencies. But i wanna see ten graphics in one figure as a result of changing "m2" value. ı have two matrices, K and M. im trying to change "m2" which is located M matrix. How can i plot natural frequencies with respect to w and m2 in one figure?
clear all
clc
syms k1 k2 w m1 m2 L L1 b b1
m1=1.816;
L=0.735;
G=80000;
dk1=3;
Dk1=44;
s=18;
k1=(G*dk1^4)/(64*s*(Dk1/2)^3)*1000
dk2=2.5;
Dk2=44;
s=18;
k2=(G*dk2^4)/(64*s*(Dk2/2)^3)*1000
m3=4.8;
L1=0.223;
m2=0;
K=[k2,-k2*L;-k2*L,(L^2)*(k1+k2)]
s=1;
A=zeros(20);
for m2=0.4:0.4:4;
s=s+2
M=[m2,0;0,m1*L^2/3+m3*L1^2]
A(s-2:s-1,s-2:s-1) = M
end
sayac=0;
for w=1:1:100
sayac=sayac+1;
umax=((K-M*(w^2))^(-1))*[150;0]
b(sayac)=umax(1);
end
w=1:1:100;
plot(w,b)
xlabel('w [rad/sn] ')
ylabel('X [mm]')
title('Sisteme Ait Doğal Frekans Grafiği')
hold on
  2 Comments
Salaheddin Hosseinzadeh
Salaheddin Hosseinzadeh on 2 Jun 2015
Hi,
Are you aware of subplot() or hold on, commands?
hold on
subplot
hamit Kenan
hamit Kenan on 3 Jun 2015
Yes i am. but my aim is to plot in the same figure with "for loop".

Sign in to comment.

Answers (1)

Salaheddin Hosseinzadeh
Salaheddin Hosseinzadeh on 3 Jun 2015
Hi Hamit,
I don't thin if you have any problem plotting in a loop, you just need to organize your data and address them with an appropriate index, have a loot at the code blow, its part of a code I wrote
for i = 1:size(PSFOffset,2)
figure
for j = 1:size(PSFOffset,1)
subplot(2,1,j)
plot(scaledSegments{j,i})
title(sprintf(['PSF Ofsset: ',num2str(PSFOffset(j,i)), ' PSF length: ',num2str(estimatedWireDiam(j,i)),...
'\nAtten(dB): ', num2str(freqMagNullVal(j,i)),' DeconvRes: ', num2str(deconvResidueFactor(j,i)),...
'\nFuzzy Grade: ',num2str(fuzzyGrade(j,i))]));
end
end
There are two for loops as you see, what you can do is to locate a hold on after the plot command which is located inside a loop and get your graphs plotted.
Let me know if you need further info ;)

Categories

Find more on 2-D and 3-D Plots 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!