stop the data comprising from 4 different loops in an array
Show older comments
Hi here is the code :
%%%%%%
for w=[0.01,0.1,0.3,0.8,3]
for K=4:9
for T=2:3
for tau=1:2
G=K*exp(-(tau*(i*w)))/(T*i*w+1);
G_n=6.5/((2.5*(i*w)+1)*(1.5*(i*w)+1));
Delta_a=G-G_n;
%%%%%%%
I want to have Delta_a consisting from an array covering all the values not the very last one Thanks
Accepted Answer
More Answers (1)
wv = [0.01,0.1,0.3,0.8,3];
Kv = 4:9;
Tv = 2:3;
tauv = 1:2;
Delta_a = zeros(numel(wv), numel(Kv), numel(Tv), numel(tauv)); % Pre-allocate
for iw = 1:numel(w)
w = wv(iw);
G_n = 6.5/((2.5*(1i*w)+1)*(1.5*(1i*w)+1)); % 1i instead of i
for iK = 1:numel(Kv)
K = Kv(iK);
for iT = 1:numel(Tv)
T = Tv(iT);
for itau = 1:numel(tauv)
tau = tauv(itau);
G = K*exp(-(tau*(1i*w)))/(T*1i*w+1);
Delta_a(iw, iK, iT, itau) = G-G_n;
end
end
end
"i" is confuced with the imaginary unit too often, so use 1i instead.
Categories
Find more on Robotics 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!