Save an array of strings as cell

조회 수: 4 (최근 30일)
H AM
H AM 2017년 5월 29일
댓글: H AM 2017년 5월 29일
Hi everyone! I'm really struggling with this one, so I would really appreciate some help. I'm developing a script that works with several folders. Therefore it first ask the user to select them. I'm using Matlab 2015 and, as far as I know, there is no way of saving an array of strings, so I'm trying to use a cell as follows:
directory{n}=[uigetdir('default path','text to show on window'), n]; %n is the loop for each folder
Later on the code I have to cd to each folder:
cd(directory{n});
but I'm getting the error "Cannot CD to (path) (Directory access failure)." Trying to solve it I saw that when I extract the string from the cell, it has a blank space at the end of it. Say for example I do this:
A=uigetdir %'D:\Desktop' selected
directory{n}=[uigetdir, n]; %'D:\Desktop' also selected
B=directory{n};
A will be a 1x10 char while B will end being a 1x11 ('D:\Desktop '). Anyone knows why it adds this space at the end. Also, trying not to loose to much time, I just tried deleting this blank space following this solutions:
But unfortunately none of them have solve it. The string still has a blank space at the end.
The full code of the while loop is:
n=0;
answer='s';
while strcmpi(answer,'s')
n=n+1;
text=['Seleccionar ubicación del set de capturas ',num2str(n)];
directory{n}=[uigetdir('D:\BIBLIOTECA\INVESTIGACION\Ultrasonidos\3_PRUEBAS',text), n];
channel(n)=input('¿En que canal está la señal a analizar? [1,2,3,4]\n');
while channel(n)>4 | channel(n)<1
disp('Respuesta incorrecta');
channel(n)=input('¿En que canal está la señal a analizar? [1,2,3,4]\n');
end
answer=input('¿Quiere añadir más ensayos? [s,n]\n ','s');
while strcmpi(answer,'s')~=true & strcmpi(answer,'n')~=true
disp('Respuesta incorrecta');
answer=input('¿Quiere añadir más ensayos? [s,n]\n ','s');
end
end
  댓글 수: 2
Stephen23
Stephen23 2017년 5월 29일
"Anyone knows why it adds this space at the end"
Because you put it there:
[uigetdir, n]
(most likely it is not a space, but some non-printing control character).
H AM
H AM 2017년 5월 29일
OMG Stephen, you are absolutely right, I was already blind. Should be just:
directory{n}=uigetdir('D:\BIBLIOTECA\INVESTIGACION\Ultrasonidos\3_PRUEBAS',text);
The other was from an older version and I just didn't realized. I fell really stupid right now. Many thanks!

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by