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 :

 採用された回答

per isakson
per isakson 2014 年 11 月 9 日
編集済み: per isakson 2014 年 11 月 9 日

0 投票

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, &nbsp cssm.m, &nbsp shall be in the same folder as the data files.

3 件のコメント

mounim
mounim 2014 年 11 月 9 日
Thank you for your help, that made a lot of sense.
mounim
mounim 2014 年 11 月 9 日
編集済み: mounim 2014 年 11 月 9 日
one last question ... When i use you code on the exemple above, it works like a charm. but when i use my actual data. i doenst work. my data looks like so : VHxBxVVxPx255x98x is it because of the length of the data list or the actual format of the data ( strings and numbers )
mounim
mounim 2014 年 11 月 10 日
i guess i figured it out .. changing %f to %20f

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

その他の回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 11 月 9 日

0 投票

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 件のコメント

mounim
mounim 2014 年 11 月 9 日
Thanks for the answer, but how can i do that, by reading the files automaticly, and the poplating "a" and "b" .. i have large list, with more than 3000 items. it will be difficult to do it manually. that why i want to read a file and save it.
Azzi Abdelmalek
Azzi Abdelmalek 2014 年 11 月 9 日
What part of the code is manual?
mounim
mounim 2014 年 11 月 9 日
編集済み: mounim 2014 年 11 月 9 日
i am sorry, then i guess i didnt understand how it works. can you explain please ? i mean shouldnt i be able to read "a" from a file ?

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

カテゴリ

ヘルプ センター および File Exchange で File Operations についてさらに検索

質問済み:

2014 年 11 月 9 日

コメント済み:

2014 年 11 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by