フィルターのクリア

Tab autocompletions in functions for paths

6 ビュー (過去 30 日間)
Andrea Somma
Andrea Somma 2023 年 10 月 7 日
編集済み: Dheeraj 2023 年 10 月 31 日
Is it possible to get paths autocompletions even in functions created by the user? For example if I create a function that gets a path as a input variable, is it possible to make sure that matlab knows that the variable is a path and checks for possible solutions in the written directory? It would be also interesting if this is made inside the function WITHOUT changing matlab settings to make it easily distributable

採用された回答

Dheeraj
Dheeraj 2023 年 10 月 26 日
編集済み: Dheeraj 2023 年 10 月 31 日
Hi,
I understand you want to know if it is possible to possible to ensure that MATLAB recognizes the input variable as a path and checks for possible solutions in the written directory.
Yes, you can do this by using the “dir” function to list all files in a directory and then use the“load” function to load the file into your function. Here is an example of how you can do this assuming the path directs to a “.mat” file.
function testfunction(pathToFile)
% Check if pathToFile is a directory
if isfolder(pathToFile)
% List all files in the directory
files = dir(fullfile(pathToFile, '*.mat'));
% Load each file into your function
for i = 1:numel(files)
data = load(fullfile(pathToFile, files(i).name));
% Do something with the data
end
else
% Load the file into your function
data = load(pathToFile);
% Do something with the data
end
end
If you wish to make this change in MATLAB settings, you could refer to this MATLAB answer that has been previously posted and answered.
Hope this helps!
  2 件のコメント
Andrea Somma
Andrea Somma 2023 年 10 月 26 日
Hey! Thank you for answering, I understand what your function does, but I don't understand how il could be run in the background to check if any paths are available to be autocompleted. I want to do exactly what you attached as link but WITHOUT changing matlab settings, so the function can be used "out of the box" in every matlab installation
Andrea Somma
Andrea Somma 2023 年 10 月 26 日
Nevermind I found out that at the end of the thread you posted there are new solutions for new matlab versions too. Thank you very much

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeIntroduction to Installation and Licensing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by