필터 지우기
필터 지우기

how to create matrix from a row vector of different elements?

조회 수: 3 (최근 30일)
scobug411
scobug411 2020년 9월 8일
편집: Adam Danz 2020년 9월 8일
for example creating y=[1 3; 2 4; 3 5] using A=[1:5]
i cannot use reshape because its a different number of elements
  댓글 수: 1
Adam Danz
Adam Danz 2020년 9월 8일
편집: Adam Danz 2020년 9월 8일
What rule are you using for that transformation? For example, what would be the output for A=1:6?
Also, relace() is used with strings so why would you use that in the first place? Or are you using a different funcition with the same name?
For the example in your question,
y = reshape(A([1:3,3:5]),[],2);
but that won't work if A has a different length.

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2020년 9월 8일
The first and second columns are consecutive elements of ‘A’ although with an offset for the second column.
This is likely the easiest way:
Y = [A(1:end-2); A(3:end)].';
.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by