I would like to know how to pass single quotations as an argument in matlab. I am running a bash script that takes in a string of integers and creates an array from it. The bash program is like this:
read -a array <<< "$1"
for i in ${array[@]}
do
echo $i
done
In the matlab GUI I want to test this function by doing this:
>> string = '1 2 3 4 5'
>> unix(['script.sh ' string])
and it gives
1
ans =
0
but it does not print out the entire array! In bash if I do…
script.sh '1 2 3 4 5'
I get
1
2
3
4
5
My theory is that matlab is taking in the numbers, and the bash script is just reading the first argument ‘1’ into the array and printing it. So if I could somehow pass the string encapsulated by single quotations then it should work.
The issue is that Matlab’s
unix()command only returns a status variable by default. You have to tell it to return the standard output as well, which is mentioned in the Matlab documentation for this function. The0value you are seeing is the status variable, and0means “success.”What you want to do is:
Also, here is a link that helps explain string formatting in Matlab and includes the example of adding a single quote into a string. This is achieved by repeating the single quote symbol twice consecutively inside the string. So ”” yields
', because inside of the two outer single-quotes, I have placed two consecutive single quotes. This is different than using the double-quote keystroke on the keyboard, which produces a double quote. So you can write the array string as: