HI, does anyone know how to make a file name as an input parameter of a function?

Discussion in 'MATLAB' started by sunnylele, May 9, 2006.

  1. sunnylele

    sunnylele Guest

    Hi, all,
    as in title, I want to define a function that read a filename as an
    input variable.
    Specifically, the M file is:
    funcition [X,Y]=fid_sigsub(dXX)

    load E:\matlab\work\dXX\popo.000

    in the command window:
    ??? Error using ==> load
    Unable to read file E:\matlab\work\dXX\popo.000: file or directory does
    not exist.

    Error in ==> E:\blddf3_28_03_06\ZQC\fid_sigsub.m
    On line 19 ==> load E:\matlab\work\dXX\popo.000;

    Does anyone know how to input a file with its directory as the input
    variable of a function defined in such a M-file?

    Many thanks,
    sunnylele, May 9, 2006
    1. Advertisements

  2. fname = fullfile('E:', 'matlab', 'work', dXX, 'popo.000');


    fname = sprintf('E:\\matlab\\work\\%s\\popo.000', dXX);
    Peter Boettcher, May 9, 2006
    1. Advertisements

  3. sunnylele

    Zing Thing Guest

    If I understand you correctly, this should work for you:


    Note that I am using it as a function and not a command.
    See load's help page.
    Zing Thing, May 9, 2006
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.