How can I export Matrices in a Cell data?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Walter Roberson
le 30 Mai 2016
Are all of the cells the same size? Are they integer data or floating point?
Réponses (1)
John BG
le 30 Mai 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
0 commentaires
Voir également
Catégories
En savoir plus sur Whos dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!