how to call a variable in single quotation

1 回表示 (過去 30 日間)
Kws
Kws 2011 年 11 月 4 日
I am trying to download files from an ftp server using the command mget.
I am reading the location from an excell file and assign them to a variable. For Example d is a vector containing the locations. d=[ web/dr.txt, web/dr1.txt] in order to download them using mget I need mget(ftp, 'web/dr.txt').
But if I don't use the single quotes it will not get it. I want to call mget(ftp, d(1)) for example. But I want the text assigned to d(1) to appear in mget with single quotes. How can I do it?
Can anyone help me please?

回答 (3 件)

Walter Roberson
Walter Roberson 2011 年 11 月 4 日
d = {'web/dr.txt' 'web/drt1.txt'};
mget(ftp, d{1})
  1 件のコメント
Kws
Kws 2011 年 11 月 4 日
If I use you or suggestion it gives the following error
??? Undefined function or method 'eq' for input arguments of type 'cell'.
Error in ==> ftp.mget at 32
if any(str == '*')

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


Jan
Jan 2011 年 11 月 4 日
No, you do not want the quotes to appear in the mget command. The quotes are displayed in the command window, when a cell string is printed. And the quotes are used to define a string in the source code. But the quotes are not part of the string.
Walter's example works, if you consider the curly braces. Using round parenthesis calls mqet with a scalar cell string, but you need the contents of the first element of this cell string:
d = {'web/dr.txt' 'web/drt1.txt'};
class(d(1)) % >> cell
class(d{1}) % >> char
Please read the Getting Started chapters of the documentation. Cell strings are explained there exhaustively.

Kws
Kws 2011 年 11 月 4 日
Thank you both. I found my own way to do it though by converting the variable to character variable. a=char(d) and then call in mget the rows of a
  1 件のコメント
Jan
Jan 2011 年 11 月 4 日
This less efficient than accing the already existing CHAR vector by d{1}.

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

カテゴリ

Help Center および File ExchangeFTP File Operations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by