필터 지우기
필터 지우기

Making cell array out of two same length vectors

조회 수: 1 (최근 30일)
Mohammed
Mohammed 2013년 5월 15일
Hi all, I am trying to make cell array out of two same length vectors, i.e. I have two vectors each is 1066 element and I want to join every element in vector1 with it’s comparative element in vector2 so that to make a cell array made of 1066 equal size vectors each of two elements. Please help

채택된 답변

Stephan M. H.
Stephan M. H. 2013년 5월 15일
편집: Stephan M. H. 2013년 5월 15일
Hi Mohammed,
if you have the two vectors x1 and x2 (each of size 1x1066) you can merge them frist to a matrix:
X = [x1;x2]
and then transform it into a cell array
C = mat2cell(X,2,ones(1,1066))
This will give you an cell-array of size 1x1066, where each cell j contains the pair X(:,j).
best,
Stephan
  댓글 수: 1
Mohammed
Mohammed 2013년 5월 15일
Thank you very much, I tried it and it is working great.

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

추가 답변 (1개)

Jan
Jan 2013년 5월 15일
C = cell(1, 1066);
for iC = 1:1066
C{iC} = [x1(iC), x2(iC)];
end
  댓글 수: 1
Mohammed
Mohammed 2013년 5월 15일
Thank you for help. The code runs for a long time and there are empty cells.

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

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by