directly use results of function

조회 수: 11 (최근 30일)
Ivan
Ivan 2014년 7월 9일
답변: Daniel 2014년 7월 9일
I would like to get 'def' from something like:
(strsplit('abc.def.ghi','.'))(2)
I don't want to do this
r = strsplit('abc.def.ghi','.')
r(2)
is this possible?
  댓글 수: 1
Azzi Abdelmalek
Azzi Abdelmalek 2014년 7월 9일
Why you don't want to do?
r = strsplit('abc.def.ghi','.')
r(2)

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

채택된 답변

James Tursa
James Tursa 2014년 7월 9일
This has been asked many time on this forum. MATLAB does not support indexing directly into a function result. This is a restriction of the language itself, not just your particular function example. So you will need to use the 2-step approach. Yes, it can clutter up your code a bit, but that's the way it is.

추가 답변 (1개)

Daniel
Daniel 2014년 7월 9일
subsref(strsplit('abc.def.ghi','.'),struct('type','{}','subs',{{2}}))
The subsref function takes two arguments. The first is the data structure (in this case a cell array of strings) and the second is a structure with two fields: type and subs. Type contains the operator which will be used to index the data structure, and the subs field contains the index you want to access.

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by