- What have you tried so far (show your code) and why do you think it isn't working? If you are getting error messages, cut and paste the entire error message (everything in red in the command window).
- How many of each "constant" should be in the final vector and what are the values of the "constants"? Just 0, 2, and 4?
- Why do you think you need a loop in the first place?
Loop to create a matrix with adding a constant value to a matrix
조회 수: 2 (최근 30일)
이전 댓글 표시
I am trying to make a loop that can save the iterations and add a contant value to a matrix.
For example,
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1466797/image.jpeg)
I am very sorry for the poor picture :( hopefully there is an easy way to do this. Thanks
댓글 수: 1
Les Beckham
2023년 8월 28일
You will need to provide more detail to get a good answer. For example:
Also, if you are just getting started with Matlab, I would highly recommend that you take a couple of hours to go through the free online tutorial: Matlab Onramp
채택된 답변
Dyuman Joshi
2023년 8월 28일
편집: Dyuman Joshi
2023년 8월 28일
You can either
- Preallocate a zero array and add elements using ones or repelem via indexing.
- Obtain the final matrix via repelem or repmat and display the sub-arrays for iteratively.
It is not recommended to dynamically grow arrays (refer to the preallocation link mentioned above for more information)
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!