フィルターのクリア

Use files from multiple folders

4 ビュー (過去 30 日間)
Nikoo Moradpour
Nikoo Moradpour 2023 年 7 月 28 日
コメント済み: Nikoo Moradpour 2023 年 7 月 31 日
Hi
I want to extract images from different videos in different folders (other than the folder for MATLAB code) but I do not want to use a separate code saved in the same directory of each video. Also I want to save the extracted images in the same directory of the original video. Is that possible?
Thanks

採用された回答

Image Analyst
Image Analyst 2023 年 7 月 29 日
Since this is one of the most common FAQs, see the FAQ for code snippets:

その他の回答 (1 件)

Jon
Jon 2023 年 7 月 28 日
Yes, this is possible.
You can either open the file using the full path to the file, for example
im = imread('c:/mystuff/myvideos/image001.jpg');
or you can change the directory down to the directory where the files are, do what you want and then go back
% Save the original folder so you can go back and navigate to new folder
oldFolder = cd('c:/mystuff/myvideos');
% Read the image, etc
im = imread('image001.jpg');
% Go back to original directory
cd(oldFolder)
You can also use relative paths. See https://www.mathworks.com/help/matlab/ref/cd.html for more details.
You can also look at the dir command that is useful to find the names of available files and folders, see https://www.mathworks.com/help/matlab/ref/dir.html
  2 件のコメント
Stephen23
Stephen23 2023 年 7 月 29 日
編集済み: Stephen23 2023 年 7 月 29 日
Using CD in code should be avoided, as it forces MATLAB to rescan those folders for all relevant files and can changes what functions get called. The documentation recommends "Avoid programmatic use of cd, addpath, and rmpath, when possible. Changing the MATLAB path during run time results in code recompilation."
Using absolute / relative filenames is faster, easier to debug, and more robust.
Nikoo Moradpour
Nikoo Moradpour 2023 年 7 月 31 日
Thanks Jon and Stephan for your help and answers.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSearch Path についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by