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

1 次查看(过去 30 天)
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 ??

采纳的回答

Kirby Fears
Kirby Fears 2016-4-6
编辑:Kirby Fears 2016-4-6
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.

更多回答(0 个)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by