Call a element of Varying Column vector

Kt=rand(6,6);
u=rand(6,6);
for i=1:1:6
for n=1:1:5
fr(:, i)=Kt*u(:,i) % i am try to call earch column of u here for multiplying with Kt, if i am wrong please correct me.
eval(['fr',num2str(n),'=Kt*u(:,i)'])
end
end
%%% Now i want to call each element of fr one by one how can i call it.

 Accepted Answer

Hard to understand what you are trying to do. Eval statement makes no sense as well as the douple for-loop. Eval would be overriding each i-loop to the same values. Why not just:
Kt=rand(6,6);
u=rand(6,6);
fr=Kt*u;
Then index into fr. To call each element in fr,
for k=1:numel(fr)
fr(k)
end

7 Comments

@David Hill , sir for fr , i have to call every column of u as column vector (6X1) not as a matrix (6X6) for each value of i.
i have to find fr1 fr2 fr3 fr4 fr5 for each column vector of u and after that i want to take each element of fr1 fr2 fr3 fr4 fr5 one by one.
fr above is the same as:
Kt=rand(6,6);
u=rand(6,6);
for i=1:6
fr(:, i)=Kt*u(:,i);
end
The n-loop makes no sense and will not change fr (no 'n' in the equation).
I don't understand your comment. Please provide an example of your expected output.
Ok Sir, in actual code u is evaluated for each loop as a 6X1, For understanding i maintned here as a 6X6 matrix.
For each loop, simultaneolsy i have to calculate fr that will be fr1, fr2, fr3, fr4,....... for each loop
now next steps in coding i have to extract each element of fr1, fr2, fr3, fr4,....
i want to know that how can i extract the each element for each fr1, fr2, fr3, fr4,....
Very bad idea to have different variable names (fr1, fr2, fr3, ...). You should have just one matrix and index into it.
Kt=rand(6,6);
for n=1:5
u=rand(6,1);%since your u changes based on calculations
fr(:,n)=Kt*u;
end
%now fr will be 6x5 matrix with each column of fr being (fr1,fr2,fr3,fr4,fr5)
%extracting elements from fr1.... is easy
element=5;fr_number=3;%if you want element 5 from fr3
fr(element,fr_number)
sir, @David Hill ,what i am exactly want, i am unable to explain here without complete code. sir i mailed you. please reply me.
@David Hill sir, please correct me.
ut=rand(15,1);
uy=([0.84;0.384;0.784]);
eval (['U_y','=[u_y;u_y;u_y;u_y;u_y]']);
for n=1:15
if ut(n,1)<=U_y(n,1)
ut(n,1)=ut(n,1);
else
ut(n,1)=0;
end
utt(:,1)=ut(n,1); %% i want to store the ut as a utt in a column
end

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!