Context
In R2016b, MATLAB introduced a new string datatype, in addition to the usual char datatype. So far, so good, but it is now giving me a lot of issues with the JSONlab toolbox I'm using.
For instance, in R2015b, loadjson
returns a 1x3 cell character array:
dd = loadjson('["Titi", "Toto", "Tata"]')
dd =
'Titi' 'Toto' 'Tata'
But in R2018a, loadjson
returns a 1x3 string array:
dd = loadjson('["Titi", "Toto", "Tata"]')
dd =
1×3 cell array
{["Titi"]} {["Toto"]} {["Tata"]}
Problem
For not having to change my code everywhere, I'd like to patch the loadjson
routine to replace all string
types it may return with char
types. For instance, in the following cell array:
test = { 'hello', "world", 0.3; 'how', 'are', "you"}
test =
2×3 cell array
{'hello'} {["world"]} {[0.3000]}
{'how' } {'are' } {["you" ]}
I'd like to replace all strings:
cellfun(@isstring, test)
ans =
2×3 logical array
0 1 0
0 0 1
Is there a way I can do it quickly (i.e. without looping through all elements) ?
PS: I know of jsondecode and jsonencode to replace JSONLab in the future, but so far I just want to quickly patch things.