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

2 ビュー (過去 30 日間)
Joel Sande
Joel Sande 2016 年 4 月 6 日
編集済み: Walter Roberson 2016 年 4 月 7 日
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.
  1 件のコメント
Joel Sande
Joel Sande 2016 年 4 月 6 日
Thanks a lot !! it works

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDebugging and Analysis についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by