Hey.
I need help trying to open a folder on matlab while the code is running. I want the folder to open as a response to the user clicking on the screen. I already have the folder in the same pathway as the overall code, I'm just having trouble with the syntax and general terminology to open a specfic folder.

댓글 수: 11

Jan
Jan 2021년 4월 11일
Please explain what you call "open a folder"? Do you want to access its contents by using fopen, or do you want to show it in a file explorer, e.g. the Windows Explorer?
Ghina Alhunaidi
Ghina Alhunaidi 2021년 4월 11일
Oh yes, I mean access its content, so if the folder's name is PuzzleOne, how would I write the code for that exactly?
Jan
Jan 2021년 4월 11일
I still cannot guess, what "access it's contents" means...
Ghina Alhunaidi
Ghina Alhunaidi 2021년 4월 11일
basically they are gonna press on the screen and I want a folder to pop up and open without them having to open the folder manually, the code would do it for them if that makes sense.
project = 'PuzzleOne';
dinfo = dir(project);
filenames = fullfile(project, {dinfo.name});
Stephen23
Stephen23 2021년 4월 12일
편집: Stephen23 2021년 4월 12일
Jan
Jan 2021년 4월 12일
@Ghina Alhunaidi: Remember, that the readers do not have the faintest idea about what you want to achieve. So explain it to us as if we were rubber ducks.
"basically they are gonna press on the screen" - who is "they" and what is "pressing on the screen"?! Do you mean: push a button in a GUI?
"and I want a folder to pop up and open without them having to open the folder manually" - "pressing on a screen" sounds like a manual opening.
A folder is a abstract construction for the organization of files. I'm sure you mean something very specific when you say "a folder pops up". So please explain explicitly, what this is. A window of the Windows Explorer? A dialog for choosing files like uigetfile? The output of dir in the command window?
Ghina Alhunaidi
Ghina Alhunaidi 2021년 4월 12일
Okay so I resolved the "clicking issue" and I'm using this line of code: ( [file,path] = uigetfile('*.mov'); ) which shows me all the folders in my desktop and allows me to click on the selected type of file:
And this allows me to open the "Window View" folder and see its contents like so:
But I'm not able to open the video. When I click on open now it just returns me back to the matlab page, which is understandable because I don't have a line of code that tells it to open the selected file. Is it possible to do that, have matlab open the selected file?
Stephen23
Stephen23 2021년 4월 12일
"Is it possible to do that, have matlab open the selected file?"
What does "open the selected file" mean exactly: open the file using its default application on your OS? Or open the file using some other non-default application on your OS? Or open the file as text within the MATLAB editor? Or do you want to actually import the file data using a suitable importing tool/function for that file format, so that you can perform further processing of the file data within MATLAB?
The more accurately you describe what you want, the easier it is for us to help you.
Ghina Alhunaidi
Ghina Alhunaidi 2021년 4월 12일
I want it to open the file using its default application
[filename,filepath] = uigetfile('*.mov');
if isempty(filename)
%user cancel, handle appropriately here
end
fullname = fullfile(filepath, filename);
open(fullname)
Using path as the name of a variable is not recommended as path controls the MATLAB search path.

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

답변 (1개)

Jan
Jan 2021년 4월 11일
편집: Jan 2021년 4월 11일

0 개 추천

Maybe you want to open a file inside this folder?
function main
myPath = fileparts(mfilename('fullpath')); % Folder of this M-file
Folder = fullfile(myPath, 'NameOfSubfolder'); % Subfolder inside
Data = load(fullfile(Folder, 'YourData.mat')); % A specific file there
...
end

카테고리

태그

질문:

2021년 4월 11일

댓글:

2021년 4월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by