Selecting part of a string

조회 수: 1 (최근 30일)
Matt
Matt 2011년 6월 14일
I have a list of file names in a variable called file_name e.g:
[a.txt b.txt c.txt d.txt]
I would like to create a new variable which only contains:
[a b c d]
Is this possible?
Thanks in advance Matt
  댓글 수: 3
Matt
Matt 2011년 6월 14일
I'm not sure what you mean, it is a 4x1 matrix (4 rows, 1 column).
Thanks,
Matt
Paulo Silva
Paulo Silva 2011년 6월 14일
You say 4 rows and 1 column but your example is 4 columns and 1 row

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

채택된 답변

Paulo Silva
Paulo Silva 2011년 6월 14일
surely not the best way to do it but here is my way
v=['a.txt' 'b.txt' 'c.txt' 'd.txt']
cell2mat(arrayfun(@(x)strtok(x,'.txt'),v,'uni',false))
or
v=['a.txt' 'b.txt' 'c.txt' 'd.txt']'
cell2mat(arrayfun(@(x)strtok(x,'.txt'),v,'uni',false))
  댓글 수: 3
Matt
Matt 2011년 6월 14일
The following kind of works:
arrayfun(@(x)strtok(x,'.txt'),file_list,'uni',false)
but in the new variable there are quotes around the text e.g
'a.txt' is it possible to remove the quotes?
Matt
Matt 2011년 6월 14일
Hi,
this works perfectly:
x = strtok(file_list,'.txt')
thanks,
Matt

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

추가 답변 (0개)

카테고리

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