2

I tried looking online for this and can’t find what I am looking for. I am trying to write a script to do something I do a lot. I would like to be able to pass in, as the command argument, the name of a file. Then my script goes off and plots it the way I want. So I need to have a character string as the input to the script. Furthermore I would like to add a check and bail if the input is not a valid character string.

So I want to do something like this… (much appreciated)

Function retval = load_3d(filename)       
    retval = 1;
    if( !(filename is character string)) // or better check if it is a CSV file :)
             retval = 0;
             Return;
    Endif

    Bla bla
    .
    .
    . 
endfunction

1 Answer 1

2

You want to use the functions ischar, exist and csvread.

function status = load_3d (filename)
    status = false;
    if (ischar (filename) &&
        (exist (filename, "file") && ! exist (filename, "dir")))
        status = true;
        data = csvread (filename);
        ## do stuff with data
    endif
endfunction

Note that a directory is just a special type of file, so exist (filename, "file") will return true for directories.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.