0

Background

I have a variable called bridgeRoot defined as such:

/over/the/river/and/through/the/woods

This directory has the following subdirectories:

/logs
/txt
/bins

In matlab command line, when I type bridgeRoot I get the value of the variable appropriately:

>> bridgeRoot

bridgeRoot = 

/over/the/river/and/through/the/woods

However, when I try to cd to a subdirectory, I get the following error

>> command = 'cd bridgeRoot/logs'

>> system(command)

Error bridgeRoot/logs: No such file or directory

status = 1

This works when done as part of a matlab script, but for some reason it fails while in command line.

Question

How do I properly refernce matlab variables when invoking a unix command in matlab command line?

2 Answers 2

3

It should be command = ['cd ' bridgeRoot '/logs'] to use the contents of your variable bridgeRoot rather than the text 'bridgeRoot'.

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

Comments

2

You are using >> command = 'cd bridgeRoot/logs', this way it's a string which is never interpreted. The best option to concatenate two parts of a path is to use the fullfile command. Further I am not sure if you want to call the matlab function cd or the os command. For the matlab function:

cd(fullfile(bridgeRoot,'logs'))

for the os command:

system(['cd ',fullfile(bridgeRoot,'logs')])

The later would only make sense once you add further commands. The cd only changes the working directory for other commands within that call of system.

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.