converting an array of n symbolic variables to a cell array with n elements

조회 수: 1 (최근 30일)
Hi
Could somebody tell me a way to convert the symbolic array [ x, y , z ] to the 3 element cell array Cell, where Cell{1} = x, Cell{2} = y, etc? You would think it should be possible to do this with mat2cell, but this converts [ x, y, z ] to the a single element cell variable, i.e., Y = cell2mat([x,y,z]) returns T{1} = [ x,y,z].
Thanks!

채택된 답변

Walter Roberson
Walter Roberson 2013년 1월 12일
num2cell() rather than mat2cell()

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 1월 12일
편집: Azzi Abdelmalek 2013년 1월 12일
syms x y z
a=[x y z]
for k=1:numel(a)
A{k}=a(k)
end
  댓글 수: 2
Leo Simon
Leo Simon 2013년 1월 12일
Thanks Azzi, was trying to do it without a loop, I hate loops on principle
José-Luis
José-Luis 2013년 1월 12일
Loops are not always evil. They can make for clearer code and are sometimes faster than the vectorized alternative.

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

카테고리

Help CenterFile 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