0

I implemented a bash script in matlab, which returns a char array with all the outputs (echo). Now I would like to use the data stored in the array, to open a file. Unfortunately, I don't know how to convert the array into a string. The following code works:

[status, output] = system('./script.sh', '-echo');
filename = [ output(1) output(2) output(3) output(4) output(5) output (6) ];

But it is not very convenient and doesn't allow different lengths of the filename. Is there an easy way to solve this?

2
  • does filename = output(:) help? Otherwise can you post the result if you type output in the command line? Commented Nov 15, 2012 at 12:42
  • filename = output(1:end-1) solved it... Commented Nov 15, 2012 at 13:31

1 Answer 1

1

Basically, character arrays are strings; there's no need to convert them.

filename = output

should do the trick.

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

1 Comment

Okay, my fault...the array had an empty cell (probably a command) at the end, so Matlab couldn't open the file. filename = output(1:end-1) solved it. Thanks!

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.