putting data from a for loop into a table using matlab and fprintf
Posted
by
user2928537
on Stack Overflow
See other posts from Stack Overflow
or by user2928537
Published on 2013-10-30T03:51:26Z
Indexed on
2013/10/30
3:53 UTC
Read the original article
Hit count: 116
I am trying to put the following data from my for loop into a table formatted so that there are 11 values of F in each column, with a total of 4 columns.
but I am always ending up with one long column of my data instead of the four columns I want. I was wondering if there is some way to put the data into a matrix and then reshape it, but I am having trouble. Any help greatly appreciated.
fprintf ('Electrostatic Forces:\n')
for r = 1:4;
q2 = 0: 1*10^-19: 1*10^-18;
for F = coulomb(q2,r);
fprintf ('%d\n',F)
end
end
Where the code for the function coulomb is
function F = coulomb (q2,r);
k = 8.98*10^9;
q1 = 1.6*10^-19;
F = k*abs(q1*q2)/r^2;
end
© Stack Overflow or respective owner