Transform rows to columns and add them at the end

조회 수: 1 (최근 30일)
Alexander Bächi
Alexander Bächi 2022년 4월 14일
댓글: Mathieu NOE 2022년 4월 14일
Hello
I have a matrix like this:
1 2 3
4 5 6
7 8 9
Now, I want to transform it to this:
1
2
3
4
5
6
7
8
9
Note, the real values are not in row, so sort is no option.
Thanks in advance.

채택된 답변

Mathieu NOE
Mathieu NOE 2022년 4월 14일
hi
simply this :
>> a = [1 2 3 ;
4 5 6;
7 8 9];
>> a(:)
ans =
1
4
7
2
5
8
3
6
9
  댓글 수: 2
Alexander Bächi
Alexander Bächi 2022년 4월 14일
Thank you. I already tried this. But the ans should be:
ans =
1
2
3
4
5
6
7
8
9
Mathieu NOE
Mathieu NOE 2022년 4월 14일
oops
this is better :)
a = [1 2 3 ;
4 5 6;
7 8 9];
b = a';
b(:)
ans =
1
2
3
4
5
6
7
8
9

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

추가 답변 (1개)

Alexander Bächi
Alexander Bächi 2022년 4월 14일
편집: Alexander Bächi 2022년 4월 14일
I found a way. Maybe not beautiful but functional:
a =
1 2 3
4 5 6
7 8 9
iii = 1;
for i = 1:rows(a);
for ii = 1:columns(a);
b(iii,1) = a(i,ii);
iii++;
end;
end;
b =
1
2
3
4
5
6
7
8
9

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by