numeric array to cell array

조회 수: 2 (최근 30일)
Mohammed
Mohammed 2013년 6월 12일
Hi
I want to convert the following numeric array to cell array of cells having two elements each. Any help?
stress = [0 20 -160 150 -40 330 -40 170 -20 180]
what is required is:
cycles = [[0 20] [-160 150] [-40 330] [-40 170] [-20 180]]
  댓글 수: 2
Jan
Jan 2013년 6월 13일
Do you mean:
cycles = {[0 20], [-160 150], [-40 330], [-40 170], [-20 180]}
?
Mohammed
Mohammed 2013년 6월 17일
yes

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

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 6월 12일
편집: Azzi Abdelmalek 2013년 6월 12일
cycles=reshape(stress,2,[])
%you can also create cell array
out=arrayfun(@(x) cycles(:,x),1:size(cycles,2),'un',0)

추가 답변 (1개)

Jan
Jan 2013년 6월 13일
편집: Jan 2013년 6월 13일
stress = [0 20 -160 150 -40 330 -40 170 -20 180];
C = num2cell(reshape(stress, 2, []).', 2);

카테고리

Help CenterFile Exchange에서 Stress and Strain에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by