How can I export Matrices in a Cell data?

1 visualización (últimos 30 días)
Bidsitlov
Bidsitlov el 29 de Mayo de 2016
Respondida: John BG el 30 de Mayo de 2016
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 comentarios
Bidsitlov
Bidsitlov el 30 de Mayo de 2016
Editada: Bidsitlov el 30 de Mayo de 2016
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 el 30 de Mayo de 2016
Are all of the cells the same size? Are they integer data or floating point?

Iniciar sesión para comentar.

Respuestas (1)

John BG
John BG el 30 de Mayo de 2016
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

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by