Pippi
Pippi

Reputation: 2571

How do I get rid of double quotes in a Matlab cell?

I have an array of cells in Matlab that all elements in the cell are expressed as:

'"something"'

How can I create an array of

'something'

?

Upvotes: 4

Views: 4725

Answers (2)

user16564444
user16564444

Reputation: 1

This does not work for numbers

regexprep(string(67), '^"|"$', '')

ans =

"67"

Upvotes: 0

Colin T Bowers
Colin T Bowers

Reputation: 18560

Here are two solutions. strrep removes all instances of double quotes, while regexprep only removes double quotes at the start and end of the string (thanks to Gunther Struyf for pointing out that the second regexprep solution would be needed in some scenarios):

>> A = {'"hello"', '"wor"ld"'}

A = 

'"hello"'    '"wor"ld"'

>> B = strrep(A, '"', '')

B = 

'hello'    'world'

>> C = regexprep(A, '^"|"$', '')

C = 

'hello'    'wor"ld'

Upvotes: 6

Related Questions