필터 지우기
필터 지우기

convert 2-D to I-D matrix

조회 수: 76 (최근 30일)
Yasmin Tamimi
Yasmin Tamimi 2011년 5월 5일
How to convert from 15*15 2D matrix to 1d matrix. This is the code I used but it seems that there is something wrong when I run it because it takes the value of the first row only??
function C=OneCamera(x,y) for i=1:15 for j=1:15 x=1 y=1
d=(i-x)^2+(j-y)^2;
if d<36 C(i,j)=1;else C(i,j)=0;
end;
end;
% S=[1 ,2] B=C(1,:) % Q=C(5,:)
S=[B B] end
Your help is highly appreciated..

채택된 답변

Andrei Bobrov
Andrei Bobrov 2011년 5월 5일
...convert from ... 2D matrix to 1d matrix...
A = randi(120,3); % matrix 2D size 3x3
S = A(:); % matrix 1D size 3x1 or
S = A(:)'; % matrix 1D size 1x3 or
S = reshape(A,[],1); % matrix 1D size 3x1 or
S = reshape(A,1,[]); % matrix 1D size 1x3

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by