How to store the result of each iteration of a forloop into an array MATLAB

How to store the result of each iteration of a forloop into an array MATLAB. I am imported data(i.e., K, L, T)matrix from simulink to workspace. I want to calculate the transfer functions in MATRIX form.
This program calculating Transfer functions.
But, when i am using this "v".
I am getting last element of the matrix.
Can you please help me, How to store all matrix elements in MATLAB.
clc
K;
L;
T;
one;
for i=1:4
for j=1:4
v=tf([K(i*j)],[T(i*j) one(i*j)], [L(i*j)])
end
end

 Réponse acceptée

Mischa Kim
Mischa Kim le 14 Fév 2014
Modifié(e) : Mischa Kim le 14 Fév 2014
Chandra, use
v{i,j} = tf([K(i*j)],[T(i*j) one(i*j)], [L(i*j)])

8 commentaires

Sir,
Still i am getting Last element .
Just to show you what is supposed to happen, copy-paste-execute the following code. You can do this in the MATLAB command window:
for ii=1:4
for jj=1:4
v{ii,jj} = ii*jj;
end
end
display(v)
I am using other loop index variables to avoid confusion with the imaginary unit, which is i and j.
Question: When you remove the semi-colons after K, L, T and execute your code, do their respective values show up in the command window?
clc
K=[-0.098 -0.036 -0.014 -0.017;
-0.043 -0.092 -0.011 -0.012;
-0.012 -0.016 -0.102 -0.033;
-0.013 -0.015 -0.029 -0.108] ;
L=[17 27 32 30;
25 16 33 34;
31 34 16 26;
32 31 25 18];
T=[122 149 158 155;
147 130 156 157;
153 151 118 146;
156 159 144 128];
one=[1 1 1 1;
1 1 1 1;
1 1 1 1;
1 1 1 1];
for i=1:4
for j=1:4
v=tf([K(i*j)],[T(i*j) one(i*j)], [L(i*j)])
end
end
Chandra, as pointed out above, replace
v=tf([K(i*j)],[T(i*j) one(i*j)], [L(i*j)])
with
v{i,j}=tf([K(i*j)],[T(i*j) one(i*j)], [L(i*j)])
@ Mischa- it might not work since the tf is a non-cell array object..
Mischa Kim
Mischa Kim le 14 Fév 2014
Modifié(e) : Mischa Kim le 14 Fév 2014
Thomas, I have succesfully used this approach before. Chandra, did you get it to work?
Ya, Thank you Mischa Kim.
Sir, It's working but. In transfer function, I want the in each and ever element same coefficients
(i.e,
tf( [K(1*1)], [T(1*1) one(1*1)], [T(1*1)])) ....
...
tf( [K(4*4)], [T(4*4) one(4*4)], [T(4*4)]))
Can you please send me code for this.

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by