# Making a matrix in a loop in MATLAB 64

Posted by **Doug Hull**,

**Category:**- Format: Video,
- Level: Basic

## 64 CommentsOldest to Newest

**1**of 64

b = bsxfun(@plus, a, (0:4).');

**2**of 64

**3**of 64

r2=1 r1=10 a=[r2:r1]; for r2 = r2:r1 G = r2/3; sigrad2 = G*a^2; endThis is just a simplification of a larger code but for the crux of the matter is, the for loop calculates vectors for sigrad2, but I would like to store each of the results in a matrix - I have watched the video where you build a vector with y = i+rand inside the loop but haven't been able to extend it to my case. I would then like to plot each of those rows in the resultant matrix against a Could you please help me in building that matrix? It seems simple but I can't figure it out Thanks in advance

**4**of 64

**5**of 64

**6**of 64

**7**of 64

**8**of 64

**9**of 64

**10**of 64

**11**of 64

```
for r = 1:3;
for c=1:3;
m(r,c) = (r+c)^2;
end;
end;
disp(m)
4 9 16
9 16 25
16 25 36
```

**12**of 64

**13**of 64

**14**of 64

**15**of 64

**16**of 64

**17**of 64

**18**of 64

**19**of 64

**20**of 64

**21**of 64

**22**of 64

**23**of 64

**24**of 64

**25**of 64

**26**of 64

**27**of 64

**28**of 64

**29**of 64

**30**of 64

**31**of 64

**32**of 64

**33**of 64

**34**of 64

**35**of 64

**36**of 64

**37**of 64

**38**of 64

**39**of 64

**40**of 64

**41**of 64

**42**of 64

**43**of 64

**44**of 64

**45**of 64

**46**of 64

**47**of 64

**48**of 64

**49**of 64

**50**of 64

**51**of 64

**52**of 64

**53**of 64

**54**of 64

**55**of 64

**56**of 64

**57**of 64

**58**of 64

**59**of 64

**60**of 64

**61**of 64

**62**of 64

**63**of 64

**64**of 64

## Recent Comments