简体   繁体   中英

character vector indexing Matlab

I have the following character vector:

test = [sprintf('(1,2)\n(1,3)\n(1,4)')]

test = 
(1,2)
(1,3)
(1,4)

How do I make the indexing so that when I type test(1) it returns (1,2). and test(2) = (1,3) And test(2) = (1,4) . Is it possible to split a character vector by new line character?

You have to use strsplit which returns a cell array

c=strsplit(test,'\n')

As this is a cell indexing is done with {} , for example c{1}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM