Writing multidimensional array to text file with fprintf

6 ビュー (過去 30 日間)
abbas zoulikha
abbas zoulikha 2023 年 6 月 11 日
コメント済み: abbas zoulikha 2023 年 6 月 12 日
I share with you some part of the code that I wrote:
for i = 45: length(time_w)
w_date_array = w_start_date + ((i-1)* time_int_w)/24;
fprintf(fid,'%s \n', datestr(w_date_array, 'yyyymmdd.HHMMSS'));
fprintf(fid, '%0.4f \t',u10(:,:,i)');
fprintf(fid, '\n');
fprintf(fid, '%0.4f\t',v10(:,:,i)');
fprintf(fid, '\n');
end
so what I get in my txt file:
19981012.000000
19981012.000000
5.3263 4.3223 1.9825 5.3291 4.0469 1.7969 5.3291 2.9290 1.2031 5.4961 2.4973 1.0461 5.7783 2.4863 0.7131
0.8126 1.6046 1.7326 1.1692 1.9758 1.7503 1.5510 1.8402 1.3870 1.8292 1.7716 1.4486 1.9328 1.7804 1.2795
But I need to get is this format:
19981012.000000
5.3263 5.3291 5.3291 5.4961 5.7783
4.3223 4.0469 2.9290 2.4973 2.4863
1.9825 1.7969 1.2031 1.0461 0.7131
0.8126 1.1692 1.5510 1.8292 1.9328
1.6046 1.9758 1.8402 1.7716 1.7804
1.7326 1.7503 1.3870 1.4486 1.2795
The size of u10 and v10 is 3*5*244 (longitude*latitude*time)

回答 (1 件)

VBBV
VBBV 2023 年 6 月 11 日
編集済み: VBBV 2023 年 6 月 11 日
fprintf(fid, '%0.4f \t\n',u10(:,:,i));
fprintf(fid, '%0.4f\t\n',v10(:,:,i));
fprintf(fid, '\n');

Delete the transpose and add the newline in fprintf

  4 件のコメント
abbas zoulikha
abbas zoulikha 2023 年 6 月 12 日
Thank's for your remark, i attached the code above
abbas zoulikha
abbas zoulikha 2023 年 6 月 12 日
@VBBV the output is (by the way i tried all these possibilities before !!):
19981012.000000
5.3263
5.3291
5.3291
5.4961
5.7783
4.3223
4.0469
2.9290
2.4973
2.4863
1.9825
1.7969
1.2031
1.0461
0.7131
0.8126
1.1692
1.5510
1.8292
1.9328
1.6046
1.9758
1.8402
1.7716
1.7804
1.7326
1.7503
1.3870
1.4486
1.2795

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

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by