Save an array of strings as cell
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Stephen23
il 29 Mag 2017
"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).
Risposte (0)
Vedere anche
Categorie
Scopri di più su Characters and Strings in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!