how to create a vector with if-else statement

3 ビュー (過去 30 日間)
suleiman abdullahi
suleiman abdullahi 2019 年 8 月 16 日
コメント済み: suleiman abdullahi 2019 年 8 月 16 日
Hello,
I have the table below and the only problem is for the highlighted column. ! want it to show me either (over-damped or underdamped oscillation) by comparing it with the damp_coefficient instead of showing me the actual values. if the damping_coeff >= to the response then the column should show overd-damped. in this case it is all overdamped. i attach the simple code i created for this.
K = [200,400,800,800,800,800,800,400,400,400]'; % different sprring constants
M = [0.5,0.5,0.5,0.5,0.5,0.5,0.5,1,2,3]'; % mass of each spring
Bc = [4,4,4,8,16,32,40,4,4,4,]'; %damping_coefficient
W = sqrt(K./M - (Bc.^2)./(4.*M.^2)); % frequency in rad/sec
V = W./(2*pi); %frequency in Hz
T_end = (10.*M)./Bc; %the time at which oscillation stops
z = 2*sqrt(K.*M); % condition for overdamp or underdamp
for k = 1:length(z)
if Bc >= z
disp('overdamped')
else
disp('underdamped')
end
end
table(K,M,Bc,z,W,V,T_end, 'variablenames', {'Spring_constant', 'mass',...
'damping_coeff','response','omega ', 'frequency', 'decay_time'})

採用された回答

madhan ravi
madhan ravi 2019 年 8 月 16 日
Bc(k) >= z(k)
  4 件のコメント
madhan ravi
madhan ravi 2019 年 8 月 16 日
編集済み: madhan ravi 2019 年 8 月 16 日
Just simply add that variable in the table() call and a valid variable name.
Note: Make sure the height of that variable is the same as the others. To alter it accordingly you’d nee to use .' .
suleiman abdullahi
suleiman abdullahi 2019 年 8 月 16 日
Thanks, that totally worked
Capture3.JPG

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

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by