How can I export Matrices in a Cell data?

I have a cell array which contains matrix data that I want to export:
x x x x x ...
x x x x x ...
Each 'x' is a different matrix written as, say, [1 2 3; 4 5 6; 7 8 9]
I want to export this cell array (with dimensions 2 by n), and I want each x matrix to be exported in standard matrix notation, not semicolon notation:
[1 2 3]
x = [4 5 6]
[7 8 9]
Therefore, when I export the data I want to have:
[1 2 3] [5 2 3]
[4 5 6] [1 2 2] ...
[7 8 9] [7 8 9]
[5 2 3] [4 5 6]
[3 5 6] [7 2 9] ...
[7 1 9] [5 2 3]
How can I do this? Thank you!

3 件のコメント

dpb
dpb 2016 年 5 月 29 日
What do you mean, precisely, by "export" here???
Bidsitlov
Bidsitlov 2016 年 5 月 30 日
編集済み: Bidsitlov 2016 年 5 月 30 日
I want to print this data as tidy as possible.
Problem with the cell data is, when I print, it is hard on the eye because of the usage of semi-colons for each new row.
I want the data to be shown as something similar to the provided example.
Thank you.
Walter Roberson
Walter Roberson 2016 年 5 月 30 日
Are all of the cells the same size? Are they integer data or floating point?

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

回答 (1 件)

John BG
John BG 2016 年 5 月 30 日

0 投票

Since you didn't mention signs, perhaps the following suffices:
A=randi([1 10],randi([3 10],1,1),randi([3 10],1,1))
[sz1A sz2A]=size(A)
B=[repmat('[',sz1A,1) int2str(A) repmat(']',sz1A,1)]
create a function with these lines, for instance fun1
function Y=fun1(X)
X2=cell2mat(X);
[sz1X sz2X]=size(X2);
Y=[repmat('[',sz1X,1) int2str(X2) repmat(']',sz1X,1)];
end
and repeat for each element of the big matrix
a simple test, to generate the big matrix, just one dimension:
% generate BigMatrix
Cell_nulls={};
for k=1:1:randi(10,1,1)
Cell_nulls=[Cell_nulls randi([1 10],randi([3 10],1,1),randi([3 10],1,1))];
end
I considered cellfun, but you may want to write it all in a text file, because you mention you want to print it anyway.
If you find this answer of any help solving your question,
please click on the thumbs-up vote link,
thanks in advance
John

カテゴリ

製品

質問済み:

2016 年 5 月 29 日

回答済み:

2016 年 5 月 30 日

Community Treasure Hunt

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

Start Hunting!

Translated by