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 CenterFile Exchange에서 FTP File Operations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by