Clear Filters
Clear Filters

write data to a .txt file

3 views (last 30 days)
shanmukh
shanmukh on 20 Feb 2013
i have
matrix A=[1 2 3 4 5], matrix B=[6 7 8 9 10]
i want to create a text file with both matrices values separated by ';'
output data must be in this form in text file
1;6;
2;7;
3;8;
4;9;
5;10;
please let me know how can i do it

Answers (2)

Thorsten
Thorsten on 20 Feb 2013
fprintf(fid, '%d;%d;\n', [A' B'])
  8 Comments
José-Luis
José-Luis on 20 Feb 2013
Then you can't do it like that. What do you want the output to be when there is only one value.
shanmukh
shanmukh on 20 Feb 2013
i used this code
fprintf(f, '%i24;\n',d,'%d;\n',q);
i am getting values of q after values of p i need them beside each other.

Sign in to comment.


José-Luis
José-Luis on 20 Feb 2013
Filling with NaN, when there are no values:
A = rand(10,1);
B = rand(15,1);
nRows = max([numel(A) numel(B)]);
your_mat = nan(nRows,2));
your_mat(1:numel(A),1) = A;
your_mat(1:numel(B),2) = B;
%...
fprintf(fid, '%d;%d;\n', your_mat')

Categories

Find more on Cell Arrays in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!