Permutations from two sets of files
12 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
HI, i am totally new to matlab i hope someone can help me achieving this. i have to text files, with a list of items ( long lists ), i want to read those lists in matlab, make a permuation between then, and save the result in new file.
exemple :

0 commentaires
Réponse acceptée
per isakson
le 9 Nov 2014
Modifié(e) : per isakson
le 9 Nov 2014
With Matlab there are mostly many ways. Especially, there are many functions to read text files. Here is a straight forward function that answers your question. Watch out for the different kinds of parentheses.
function cssm()
fid = fopen( 'file1.txt' );
cac = textscan( fid, '%f' );
fclose( fid );
num = cac{1};
fid = fopen( 'file2.txt' );
cac = textscan( fid, '%s' );
fclose( fid );
str = cac{1};
fid = fopen( 'file3.txt', 'w' );
for ii = 1 : length( num )
for jj = 1 : length( str )
fprintf( fid, '%1d - %1s\n', num(ii), str{jj} );
end
end
fclose( fid );
end
This code stored in an file with the name,   cssm.m,   shall be in the same folder as the data files.
3 commentaires
Plus de réponses (1)
Azzi Abdelmalek
le 9 Nov 2014
a={1;2;3;4}
b={'A';'B';'C'}
[ii,jj]=ndgrid(1:numel(a),1:numel(b))
out=cellfun(@(x,y) [num2str(x) '-' y ],a(ii(:)),b(jj(:)),'un',0)
3 commentaires
Voir également
Catégories
En savoir plus sur Large Files and Big Data dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!