Simple question, array of strings

조회 수: 2 (최근 30일)
Marc-Olivier Labrecque-Goulet
Marc-Olivier Labrecque-Goulet 2017년 3월 2일
댓글: John BG 2017년 3월 2일
Hi, I need to creat a very simple list of 2 strings.
list1 = ['random_string1','random_string2'];
Then, I want to create a list of these values.
Array1 = [list1,list2,list3];
  • I need to be able to access one of those string easily.
  • every string will be a different lenght and cant be determined
  • I cant use the function: var =string(one,two,three); because im using MatlabR2015
  • anyone have an idea, i guess it cant be that hard but i dont have much experience with matlab.

채택된 답변

John BG
John BG 2017년 3월 2일
편집: John BG 2017년 3월 2일
Walter is right, with no additional details, type cell is the preferred class for building arrays of varying length strings:
list1 = {'random_string1','random_string2'}
list1 =
'random_string1' 'random_string2'
to access one of the strings in list
list1{1}
=
random_string1
to access one character in one string of list1
list1{1}(1)
=
r
to generate the array of lists, one way could be
Array=[list1;list2;list3]
Array =
'random_string1' 'random_string2'
'random_string1' 'random_string2'
'random_string1' 'random_string2'
to access one of the strings in array, one can either use linear indices
Array{1}
=
random_string1
Array{end}
=
random_string2
or sub-indices
Array{2,2}
=
random_string2
to access a list in string, use :
Array{1,:}
=
random_string1
=
random_string2
and to access a single character in Array
Array{1,1}(1)
=
r
if you find this answer useful would you please be so kind to mark my answer as Accepted Answer?
To any other reader, please if you find this answer of any help solving your question,
please click on the thumbs-up vote link,
thanks in advance
John BG
  댓글 수: 2
Marc-Olivier Labrecque-Goulet
Marc-Olivier Labrecque-Goulet 2017년 3월 2일
wow! ty so much for your answer, that cleared things out a lot. I would have 1000 more questions but it getting late.
John BG
John BG 2017년 3월 2일
Monsieur Labrecque
please go ahead and and ask more question that we will endeavour to answer to the best of our knowledge
Merçi Beacoup
John BG

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2017년 3월 2일
list1 = {'random_string1','random_string2'} ;
And to access individual strings you need to use {} instead of ()

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by