how to store a matrix obtained from for loop into a larger matrix

2 views (last 30 days)
for i=1:99;
for j=1:99;
G(i,j)=((atom_1HHP(i).xyz-atom_1HHP(j).xyz)*transpose(atom_1HHP(i).xyz-atom_1HHP(j).xyz))/(norm(atom_1HHP(i).xyz-atom_1HHP(j).xyz)*norm(atom_1HHP(i).xyz-atom_1HHP(j).xyz));
end
end
here atom_1HHP.xyz is a column vector of size 3*1 the value of G(i,j) gives you a matrix of size 3*3.so there is a problem with iteration. somehow the value of G(i,j) cannot be assigned.can anyone help me solve this issue. what is the command i need to use to get the value of G.the final dimension of G is 297*297.

Answers (1)

dpb
dpb on 29 Mar 2015
Yours will work if you build G(i,) as a cell array by enclosing the RHS in the "curlies" {} instead of parens. Then cell2mat on the end result well convert it to a 2D double array.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!