How to write in a file, a random string from a cell ?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Joel Sande
el 6 de Abr. de 2016
Editada: Walter Roberson
el 7 de Abr. de 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 comentarios
Respuesta aceptada
Kirby Fears
el 6 de Abr. de 2016
Editada: Kirby Fears
el 6 de Abr. de 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.
Más respuestas (0)
Ver también
Categorías
Más información sobre JSON Format en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!