Cell to String

조회 수: 1 (최근 30일)
Ajay Kumar
Ajay Kumar 2012년 3월 7일
Hi,
I am trying to concatenate a two strings in the below code:
baseDIR = 'C\Documents and Settings\User\Desktop\';
tstFeats = {'PostEq', 'AEC'};
refDir = strcat(baseDIR, tstFeats);
fileList = dir([refDir '\*.wav']);
the command dir does not work on input of type cell. I would like to convert the type cell to string to enable the working of the above code.
If I replace tstFeats = {...} with tstFeats = [...], the code works fine. But all elements in the second case need to be of the same length if I need to make a column vector.
Any help is appreciated.
Thank you.

답변 (1개)

Walter Roberson
Walter Roberson 2012년 3월 7일
There does not seem to be much point in this, as dir() can only accept a single specification per call.
Please also recall that the structure of information returned by dir() does not indicate the directory anywhere, so if you did somehow manage to get dir() to look in two directories on the same call, you would not be able to tell which directory any particular returned file name had come from.
  댓글 수: 2
Ajay Kumar
Ajay Kumar 2012년 3월 8일
Hello Walter. Nice to hear from you :)
Actually, I have the above in a for-loop which considers one folder at a time. It would be very helpful if there is any kind of work around and will save me a lot of time.
It would sufficient if I could have the following work:
a = {'ab', 'abc'};
b = a(1);
Now variable b should be assigned as a string and should not hold values as a cell.
The work around I thought of:
a = ['abc'; 'def']; % Column vector with all rows of same size
b = a(1,:);
Now b is a string. But, in this method I will not have the flexibility of choosing different sizes for the elements in Column matrix a.
Walter Roberson
Walter Roberson 2012년 3월 8일
b = a{1}

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by