How to change folders in MATLAB App Designer ?
38 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (2 件)
Steven Lord
2022 年 9 月 7 日
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 件のコメント
Kevin Holly
2022 年 9 月 7 日
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 件のコメント
Kevin Holly
2022 年 9 月 28 日
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.
参考
カテゴリ
Help Center および File Exchange で Search Path についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!