How to fill matrix in for loop?
Show older comments
I need to fill matrix r, where r=r(z), and ri is constant. But with this code I onlu get the first row where r=-0.7:0.7.
z=-1:0.001:0;
ri=0.7;
R=ri-z*(ri-1);
for z=-1:0.001:0;
r=(linspace(-(ri-z*(ri-1)),ri-z*(ri-1),1001))
end
My full matrix need to be in this shape, or transpose of this:
-0.7...... 0.7
0.8 ... 0.8
. .
. .
. .
0 .9 ... 0.9
. .
. .
. .
1 ... 1
Accepted Answer
More Answers (1)
z=-1:0.001:0;
ri=0.7;
R=ri-z*(ri-1);
[R,Z] = meshgrid(z,R) ;
r = R-Z.*(R-1) ;
1 Comment
Categories
Find more on Resizing and Reshaping Matrices 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!