I've two matrix output from two Matlab scripts and I'd like to write both results in different columns of the same GUI output in a txt file. Could you please help me?
Asked
Active
Viewed 57 times
-3
-
`horzcat` the two matrices if they have the same number of rows, pad it with zeros or NaN if they do not have the same number of rows. Use `reshape` if needed. – GameOfThrows Nov 12 '15 at 12:20
1 Answers
1
I tried some different methods (try to create cell array, or use fprintf
for arrays of different sizes) and understood that @GameOfThrows's method is really works.
I realize it in this way:
x = [1 2 3 4 5];
y = [10 20 30 40 50 60 70 80 90];
[m,i] = max( [numel(x) numel(y)]);
if i == 1
y(end+1:numel(x))=NaN;
else
x(end+1:numel(y))=NaN;
end
a = [x; y];
fileID = fopen('data1.txt','w');
fprintf(fileID,'%6.2f %12.2f\r\n',a);
My data1.txt
:
1.00 10.00
2.00 20.00
3.00 30.00
4.00 40.00
5.00 50.00
NaN 60.00
NaN 70.00
NaN 80.00
NaN 90.00

Community
- 1
- 1

Mikhail_Sam
- 10,602
- 11
- 66
- 102