directly use results of function
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
Akzeptierte Antwort
James Tursa
am 9 Jul. 2014
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.
0 Kommentare
Weitere Antworten (1)
Daniel
am 9 Jul. 2014
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.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Structures finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!