How to write in a file, a random string from a cell ?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Joel Sande
il 6 Apr 2016
Modificato: Walter Roberson
il 7 Apr 2016
HI, I would like to know how to solve this: The fprintf doesn't work because of variable conn referring to a cell.
Connect = {'A','I','O'};
r = randi(3);
strength = randi(10);
conn = Connect(r);
dir_file = '\..my path..\'; % you should change this to your path
fid = fopen(dir_file, 'a');
fprintf(fid,'%s %s %s\n', num2str(Neighboor), conn, num2str(strength));
% fprintf doesn t work here because of conn referring to a cell
What can I do ??
0 Commenti
Risposta accettata
Kirby Fears
il 6 Apr 2016
Modificato: Kirby Fears
il 6 Apr 2016
Joel,
As the error indicates, fprintf() does not accept cell inputs. The conn variable is a 1x1 cell while the other inputs are strings.
You can make "conn" a string by extracting the cell contents instead of setting conn equal to a 1x1 cell.
Just change:
conn = Connect(r);
Into:
conn = Connect{r};
The curly braces indicate content extraction from the r'th cell of Connect instead of assigning conn to the r'th cell itself.
Hope this helps.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su JSON Format in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!