How can I convert 2-D array to 1-D array.

I am using a variable oprtn_pts. whose size is 3 2.
I want to convert this into 6*1. How can I do this?

 채택된 답변

Andrei Bobrov
Andrei Bobrov 2012년 9월 18일

0 개 추천

one way
out = oprtn_pts(:);
or
out = oprtn_pts.';
out = out(:);
other:
out = reshape(oprtn_pts,[],1);
or
out = reshape(oprtn_pts.',[],1);

추가 답변 (1개)

Wayne King
Wayne King 2012년 9월 18일
편집: Wayne King 2012년 9월 18일

0 개 추천

oprtn_pts = randn(3,2);
oprtn_pts = reshape(a,6,1);
It takes the elements from oprtn_pts columnwise.

댓글 수: 3

Bhavnish
Bhavnish 2012년 9월 18일
Wayne, I want to generalize this case. Now, let's assume that I don't know what is size of oprtn_pts. I am getting this size by using command s = size(oprtn_pts); Now say that s = m n (We don't know what is there inside). How can I convert this into 1-D array? Please suggest something on this.
Andrei Bobrov
Andrei Bobrov 2012년 9월 18일
Hi Bhavnish! Please see my answer.
Bhavnish
Bhavnish 2012년 9월 18일
Hi Andrei, Thanks a lot for the help. I din't refresh my page earlier, so wasn't able to see your response. Yeah, your response is working absolutely fine for me... :-)

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

카테고리

도움말 센터File Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by