0

i have a cell of several matrices (all double and with the same dimension)

my_cell = 

    [172x15 double]    [172x15 double]    [172x15 double]    [172x15 double]

I would to write the matrices on txt file side by side and tabulated, to obtain a .txt file with 172 rows and 60 columns (in this case)

3 Answers 3

2

use dlmwrite and cell2mat

mat = cell2mat(my_cell);
delimiter = ' ';  % // used to separate two values in a row in the file
filename  = 'test.txt';
dlmwrite(filename,mat,delimiter);
Sign up to request clarification or add additional context in comments.

3 Comments

ok, thank you. If I would to select only some columns of the matrices? Do you have an idea? Should I open a new topic?
I tried with: mat = cell2mat(my_cell(i)); my_mat = mat(1:end, 1:12);dlmwrite(filename,mat,delimiter); but the file is overwritten by the i-mat
@Mixo make a new matrix using cat as new_mat = cat(2,mat(:,col_start1:col_end1),mat(:,col_start2:col_end2),.....); and if you want to select only some columns then I believe you want to store it in a new file. But if you want to append the earlier file then use dlmwrite('my_earlier_File.txt',new_mat,'-append',... 'delimiter',' ');
2
>> dlmwrite('file1.txt', [c{:}],'delimiter','\t','precision','%.5f') 

or

>> dlmwrite('file2.txt', c(:)','delimiter','\t','precision','%.5f') 

You have to choose a precision, otherwise you'll get non-uniform lines because of different numbers of decimal places.

Comments

1

Code

%// output_filepath is the name of your output text file

c1 = horzcat(my_cell{:})
datacell = mat2cell(c1,ones(1,size(c1,1)),ones(1,size(c1,2)))
dlmwrite(output_filepath,datacell,'\t'); %// a TAB delimiter is used

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.