How to change folders in MATLAB App Designer ?
41 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I am new to the App Designer and have code from an old Matlab app designer script (GUIDE). The old GUIDE works perfectly fine even after migrating it to App Designer. Unfortunately, I have to create it from another from zero, so I am using the code after migration. Changing folders through the code gives me an error on MATLAB.
When trying to go to the folder with the name \Concentrated-PanelZone-Pushover-Output, it goes to a folder with this destination \Concentrated-PanelZone-Pushover-Output\Concentrated-PanelZone-Pushover-Output, instead of just one. Then, It gives me the following error:
Error using cd
Unable to change current folder to....
(Name is nonexistent or not a folder).
Error in cd(cambio);
0 Kommentare
Antworten (2)
Steven Lord
am 7 Sep. 2022
I would advise you to use fullfile to assemble your file paths rather than concatenation. I'd also be wary about assuming that pwd is the directory that you expect it to be. If you were assuming that the present working directory was the directory that contains your GUI code, that could be an invalid assumption if the directory containing your GUI was on the MATLAB search path instead.
As an example, let's say we had a directory anotherDirectory under the temporary directory whose name is returned by tempdir.
cd(tempdir)
mkdir anotherDirectory
Let's add anotherDirectory to the path.
addpath(fullfile(pwd, 'anotherDirectory'))
If we create a file in that directory:
cd anotherDirectory
!touch myfile.txt
and change directory back to tempdir, the file is still visible to MATLAB since anotherDirectory is on the path:
cd ..
which -all myfile.txt
But trying to access it using pwd won't work.
pwd
[fid, message] = fopen(fullfile(pwd, 'myfile.txt'))
You'd need to ask for it in anotherDirectory.
[fid, message] = fopen(fullfile(pwd, 'anotherDirectory', 'myfile.txt'))
Let's close the file.
fclose(fid);
0 Kommentare
Kevin Holly
am 7 Sep. 2022
pwd gives the present working directory. The code saves it as aux_dir.
aux_dir = pwd
The line below appends aux_dir with the string attached
cambio=[aux_dir '\Concentrated-PanelZone-Pushover-Output']
I believe your aux_dir was equal to
aux_dir = '\Concentrated-PanelZone-Pushover-Output';
So, you would get this:
cambio=[aux_dir '\Concentrated-PanelZone-Pushover-Output']
3 Kommentare
Kevin Holly
am 28 Sep. 2022
If the current path doesn't contain 'Concentrated-PanelZone-Pushover-Output',
if ~contains(pwd,'Concentrated-PanelZone-Pushover-Output')
cambio=fullfile(pwd,'Concentrated-PanelZone-Pushover-Output');
cd(cambio)
end
Is there a reason you are changing the directory? Is it just to load a particular file? If so, you can do that without chainging the directory and just placing the fullpath of file as an input to the load function.
Siehe auch
Kategorien
Mehr zu Search Path finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!