Adding loop values to an array
显示 更早的评论
Hello,
I'm trying to perfom a simulation that will calculate a value for a given input and then store than input in an array such that I can graph it. However, i can't seem to be able to store the values in an array. I'm brand new to MATLAB.
Any help would be greatly appreciated.
PS, I have tried to comment the code and make what I want to happen as clear as possible.
PPS, please note, should result in a real and imaginery part.
ctc, clear
%declaring variables
rho = 1.22;
c0 = 344;
fillRat = 0.098;
dampRat = 0.03;
Fr = 417;
K = rho*(c0)^2;
Kr = rho*(c0)^2;
%%calcaulating Keff
%define mamFrequency range:
mamFrequency = 200 : 600;
%Loop through each value of mamFrequency
for j = mamFrequency
omegR = j/Fr; %dependancy--
Keff = K/((1 - fillRat) + (K/Kr)*(fillRat/(1 + 2i * dampRat * omegR - (omegR)^2)));%analytical equation
%calculating Keff/K
modulRat = Keff/K; %want to store modulRat value for each iteration of so can plot later
end
%plotting modulRat (y-axis) against i - the mamFrequency value (x-axis)
figure(1)
plot(j,modulRat);
采纳的回答
更多回答(1 个)
Richard Fiifi Annan
2021-4-1
1 个投票
real_part = real(modulRat );
imaginary_part = imag(modulRat );
figure
plot(mamFrequency, real_part, 'r', mamFrequency, imaginary_part,'b')
legend({'real part', 'imaginary part'})
类别
在 帮助中心 和 File Exchange 中查找有关 Image Arithmetic 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!