How to get Command Window format for existing 'Cell Arrays'

1 回表示 (過去 30 日間)
Ganesh Hegade
Ganesh Hegade 2016 年 11 月 9 日
コメント済み: Image Analyst 2016 年 11 月 15 日
I have a Cell-array created and i want to get the command window format for that cell-array.
For example: I have created a 5x2 cell array using command line:
MyCell = {'time' , 'timestamp';'posX', {'DePositionX', 'DePositionXmm'};'posY', {'DePositionY', 'DePositionYmm'};'velocityX', 'DeVelocityX';'velocityY', 'DeVelocityY'};
Similarly I have a MxN cell array already created(not by me) and i want to get the structure of that cell in a command window format as shown in the above code. Can you tell me is there any way or commands to get this.
Thanks.
  2 件のコメント
Adam
Adam 2016 年 11 月 9 日
What do you mean by "command window format"?
Just type
MyCell
is you want to view it in the command window.
Ganesh Hegade
Ganesh Hegade 2016 年 11 月 9 日
I can create a cell by typing below piece in command window.
{'time' , 'timestamp';'posX', {'DePositionX', 'DePositionXmm'};'posY', {'DePositionY', 'DePositionYmm'};'velocityX', 'DeVelocityX';'velocityY', 'DeVelocityY'};
Now, already i have a cell array and i want it in above format(vice-versa)

サインインしてコメントする。

採用された回答

Jan
Jan 2016 年 11 月 10 日
You have a cell array and want to create the code, which produced this array. Right? Then try FEX: uneval .
If the elements of the cell are all strings or numbers, this would work also:
S = size(C);
fprintf('C = {');
for iR = 1:S(1)
for iC = 1:S(2)
data = C{iR, iC};
if ischar(data)
fprintf('''%s''', data);
elseif isnumeric(data)
fprintf('''%g''', data);
else
error('Class not supported.')
end
if iC < S(2)
fprintf(', ');
else
fprintf('...\n');
end
end
end
fprintf('};')
  4 件のコメント
Ganesh Hegade
Ganesh Hegade 2016 年 11 月 15 日
Sure. I will note it.
Image Analyst
Image Analyst 2016 年 11 月 15 日
Isn't that just a manual way of doing
celldisp(yourCellArray);

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2016 年 11 月 9 日
編集済み: Image Analyst 2016 年 11 月 10 日
Not sure what you want but perhaps the whos() function or celldisp() would be what you want.

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by