Why am i getting this error in the following line of code?

6 ビュー (過去 30 日間)
Rizwana
Rizwana 2014 年 3 月 9 日
コメント済み: Rizwana 2014 年 3 月 10 日
disp (' ');
name = input ('Enter a name for the folder (single quotes): '); % input folder's name
mkdir (name);
It was running fine when i tested it... 'Test' by giving this string name
disp (' ');
name = inputdlg ('Enter a name for the folder (single quotes): '); % input folder's name
mkdir (name);
now when i enter a string 'Test' as my folder name in this dialogue box i get error which says...
Error using mkdir
Argument must contain a string.

採用された回答

Mischa Kim
Mischa Kim 2014 年 3 月 9 日
Rizwana, in this case use
name = inputdlg ('Enter a name for the folder (single quotes): ');
mkdir (name{1});
Note the curly brackets.
  3 件のコメント
Mischa Kim
Mischa Kim 2014 年 3 月 9 日
As pointed out above and explained by Jan below, inputdlg returns a cell array of strings. The following code snippet shows how to read and output multiple (2) lines of strings:
prompt = {'Input dialog'};
name = 'Input dialog';
numlines = 2;
dlg_ans = inputdlg(prompt, name, numlines);
dlg_ans{1}(1,:)
dlg_ans{1}(2,:)
Rizwana
Rizwana 2014 年 3 月 10 日
Thank you

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

その他の回答 (1 件)

Jan
Jan 2014 年 3 月 9 日
Please read the documentation of inputdlg . There you find the explanation, that a cell is replied. But mkdir requires a string.
You have to pick a certain element out of the cell.
See:
doc inputdlg
doc cell
doc mkdir

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by