How to write in a file, a random string from a cell ?

1 visualizzazione (ultimi 30 giorni)
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 ??

Risposta accettata

Kirby Fears
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)

Community Treasure Hunt

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

Start Hunting!

Translated by