필터 지우기
필터 지우기

separate x, y coordinate in a matrix into two different matrices

조회 수: 4 (최근 30일)
Ray
Ray 2015년 10월 5일
답변: Andrei Bobrov 2015년 10월 6일
I have 18 by 18 matrix with each cell has [-1;1] [-1;1] etc.. I want to separate this matrix into two 18 by 18 matrices. The first matrix would only have the first row for example, -1,-1 and the second matrix would have the second column for example 1, 1.
  댓글 수: 2
Walter Roberson
Walter Roberson 2015년 10월 5일
I am not clear on what the size is of each element of the cell array?
Ray
Ray 2015년 10월 6일
each cell in the 18 by 18 matrix is 2 by 1 cell i.e. [-1;1] which represents the [x;y]. I need to separate the all x's in one matrix and all the y in another matrix.

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

답변 (3개)

Walter Roberson
Walter Roberson 2015년 10월 6일
x = cellfun(@(C) C(1), YourCell);
y = cellfun(@(C) C(2), YourCell);

Image Analyst
Image Analyst 2015년 10월 5일
Assuming it's a normal numerical matrix and not a cell array, try this:
firstRow = yourMatrix(1,:); % Extract first row.
secondRow = yourMatrix(2,:); % Extract second row.
  댓글 수: 2
Image Analyst
Image Analyst 2015년 10월 5일
Oh, sorry, you said you want the first row and the second column, not second row. To get the second column, you'd do this:
secondCol = yourMatrix(:, 2); % Extract second column.
Ray
Ray 2015년 10월 6일
each cell of the 18 by 18 matrix looks like this [x;y] or [-1;1]. what i want to do is have all the x in one matrix and y in another matrix.

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


Andrei Bobrov
Andrei Bobrov 2015년 10월 6일
cell2mat(cellfun(@(x)reshape(x,1,1,[]),C,'un',0))

카테고리

Help CenterFile Exchange에서 Word games에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by