Simple Indexing problem when creating a matrix
조회 수: 1 (최근 30일)
이전 댓글 표시
I have this vector
A=[0 60 120 180 240 300 360];
And I have a variable n. Lets say n=24. I neet a matrix with the first row A and the other rows add to each element 360, n times so n rows.
A=[0 60 120 180 240 300 360;
360 420 ...............;
720 ...................];
How can I do it? I have tried with a for loop but had no success
댓글 수: 0
채택된 답변
추가 답변 (1개)
Drew
2023년 11월 28일
This is an easy question for the MATLAB AI Chat Playground https://www.mathworks.com/matlabcentral/playground/new (see announcement at https://blogs.mathworks.com/community/2023/11/07/the-matlab-ai-chat-playground-has-launched/). I asked your question and got a working response.
Code in runnable form:
A = [0 60 120 180 240 300 360];
n = 24;
B = repmat(A, n, 1) + (0:n-1)'*360;
B
Image form of the question and answer. Note that I added "Write MATLAB code to do the following" at the start of your question, telling the AI to write the code.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1554442/image.png)
댓글 수: 1
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!