How to vectorize writing to a txt file
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi there,
I have to write a function in matlab to create a txt file with the following format:
(x(1),y(1)),(x(2),y(2)),...(x(end),y(end))
I have the following piece of code (whre L is the length of vectors x and y)
for r=1:L;fprintf(fileOutput,['(',num2str(time(r)),',',num2str(signal(r)),'), ']);end
which obviously does the trick but I was wondering if anybody knows how to vectorize the expresion so that it runs much faster.
Any help will be welcomed!!
Thank you!
0 commentaires
Réponse acceptée
Plus de réponses (1)
esbolico
le 24 Avr 2013
1 commentaire
Cedric
le 24 Avr 2013
Dear Esbolico,
The interesting "thing" with SPRINTF and FPRINTF, is that they will repeat the format (here '(%f,%f),') as many time as needed to print all elements of the array(s) that are given to them. It is certainly useful when you want to avoid writing loops. I'm glad it helped!
Regards
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!