File Exchange

image thumbnail

IsPath

version 1.0 (1.57 KB) by

Checks for and displays user specific path definitions

3.66667
3 Ratings

0 Downloads

Updated

View License

Working on several projects - m-files each in a separate folder - needs the knowledge about the current folder in the search path. IsPath checks for user specific folder(s) in the search path.
p = IsPath(<foldername>); %returns true or false

p = IsPath; %returns a string with all user specific path(s). Can be used by rmpath(p) to remove all specific path definitions

Comments and Ratings (8)

Good function. Useful. Slightly outdated, but works well.

Here is my minimalistic version:

function [tf] = ispath(inp)
%% [tf] = ispath(inp)
% Checks whether the input is on the current path
sp = textscan(path, '%s', 'Delimiter', ';');
ip = cellfun(@(x) isequal(x,inp),sp);
tf = any(ip{:});
end

Good function. Useful. Slightly outdated, but works well.

Here is my minimalistic version:

function [tf] = ispath(inp)
%% [tf] = ispath(inp)
% Checks whether the input is on the current path
sp = textscan(path, '%s', 'Delimiter', ';');
ip = cellfun(@(x) isequal(x,inp),sp);
tf = any(ip);
end

Ben

Ben (view profile)

Thanks! Saved me from having to write this myself!

Ben

Ben (view profile)

Evgeny Pr

Evgeny Pr (view profile)

@Jan Simon,
RandStream this is the class. For class names is well-suited. I agree that the functions can be called a convention "camelCase" (for example: fastSort).

Jan Simon

Jan Simon (view profile)

@Evgeny: Using (sulking)camel-case for user defined functions has a great advantage: If someone reads the code, it is obvious, if a certain function is user-defined or a toolbox function of Matlab -- but e.g. RandStream is not lower case also.

Evgeny Pr

Evgeny Pr (view profile)

fix: outs = false(size(MyPaths))

4. For support crossplatform need to check the case-sensitive file system.

5. Rename IsPath to ispath (good MATLAB coding style)

This trivia :)

Evgeny Pr

Evgeny Pr (view profile)

Hi,

1. You need to remove the last file separator (or all excess separators) in checked path.

Example:
IsPath('mypath') => true
IsPath('mypath\') => false

2. More simple check method (instead of loop):
if isempty(intersect(MPath, Pfad))
tf = false
else
tf = true
end

3. Supports checking multiple paths
Example:
IsPath({'mypath1', 'mypath2', 'mypathN'})
Out for example:
0, 1, 0

Implementation:
MyPaths - cell array of checked paths

outs = false(numel(MyPaths))
[~, inds] = intersect(MyPaths, MPath)
outs(inds) = true;

Good luck!

MATLAB Release
MATLAB 7.11 (R2010b)
Tags Add Tags

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Win prizes and improve your MATLAB skills

Play today