write char array and num to textfile using fprintf

4 vues (au cours des 30 derniers jours)
Thomas Halbedl
Thomas Halbedl le 14 Mar 2018
Commenté : Thomas Halbedl le 14 Mar 2018
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 commentaires
dpb
dpb le 14 Mar 2018
Sometimes loops are the real answer, even in Matlab...
Stephen23
Stephen23 le 14 Mar 2018
"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

Connectez-vous pour commenter.

Réponse acceptée

Stephen23
Stephen23 le 14 Mar 2018
Modifié(e) : Stephen23 le 14 Mar 2018
>> a = ['ab';'cd'];
>> b = [1;2];
>> c = [cellstr(a),num2cell(b)].';
>> fprintf('%s; %f\n',c{:})
ab; 1.000000
cd; 2.000000
  1 commentaire
Thomas Halbedl
Thomas Halbedl le 14 Mar 2018
thank you so much on your quick solution. That's what I'm looking for.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by