How to change folders in MATLAB App Designer ?
25 views (last 30 days)
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);
Steven Lord on 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.
Let's add anotherDirectory to the path.
If we create a file in that directory:
and change directory back to tempdir, the file is still visible to MATLAB since anotherDirectory is on the path:
which -all myfile.txt
But trying to access it using pwd won't work.
[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.
Kevin Holly on 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
I believe your aux_dir was equal to
aux_dir = '\Concentrated-PanelZone-Pushover-Output';
So, you would get this: