write char array and num to textfile using fprintf

6 ビュー (過去 30 日間)
Thomas Halbedl
Thomas Halbedl 2018 年 3 月 14 日
コメント済み: Thomas Halbedl 2018 年 3 月 14 日
hi, i have one column char array (e.g. a = ['ab'; 'cd']) and one column vector with nums (e.g. b = [1;2]). how can i write this to a txt-file without using a loop. I tried fprintf('%s; %f\n', a, b), but it doesn't satisfying me.
Thank you
  2 件のコメント
dpb
dpb 2018 年 3 月 14 日
Sometimes loops are the real answer, even in Matlab...
Stephen23
Stephen23 2018 年 3 月 14 日
"i have one column char array (e.g. a = ['ab'; 'cd'])"
That char array actually has two columns:
>> a = ['ab'; 'cd'];
>> size(a,2)
ans = 2

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

採用された回答

Stephen23
Stephen23 2018 年 3 月 14 日
編集済み: Stephen23 2018 年 3 月 14 日
>> a = ['ab';'cd'];
>> b = [1;2];
>> c = [cellstr(a),num2cell(b)].';
>> fprintf('%s; %f\n',c{:})
ab; 1.000000
cd; 2.000000
  1 件のコメント
Thomas Halbedl
Thomas Halbedl 2018 年 3 月 14 日
thank you so much on your quick solution. That's what I'm looking for.

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

その他の回答 (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