Write data to text file

22 ビュー (過去 30 日間)
Teresa Rotava
Teresa Rotava 2019 年 9 月 17 日
回答済み: Rik 2019 年 9 月 17 日
I looked in many Answers, but I did not find someone with a similar problem. And I cannot see where I am doing the mistake.
I have raw data and I have to work in some parameters. I want to save these new results in a new .txt file. However, when I create the .txt file, the results of all parameters are horizontally distributed and not vertically.
I tried to write the parameters separately, but the same thing happened.
Data = importfile(filename);
xyz = table2array(Data(2:end,2:end)); %raw data
xyz = xyz/100;
Depth = table2array(Data(2:end,1)); %raw data
Depth = Depth + Elevation;
LAB = xyz2lab(xyz,'WhitePoint','d65');
T = [Depth, xyz, LAB]; %Matrix with new results
fileID = fopen('cl024_01.lab.txt','w');
fprintf(fileID,'Depth X Y Z L a b\n\n');
fmt = '%5f %5f %5f %5f %5f %5f %5f\r\n';
fprintf(fileID,fmt,T);
fclose(fileID);
Thank you in advance!

採用された回答

Rik
Rik 2019 年 9 月 17 日
This is probably due to Matlab being column-based, instead of row-based. This may result in counterintuitive results if you enter a matrix into fprintf. You should either transpose your T variable, or enter them separately:
fprintf(fileID,fmt,T.');
%generally easier to understand:
%fprintf(fileID,fmt,foo,bar,foo_bar);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by