Problem 2159. A SUBSREF variant that accepts the 'end'-operator.

Unfortunately, Matlab's subsref function does not support the end -operator. The end -operator is a powerfull method to refer to the rear-end of an array,

 a = 1:10;
 a(end-1) % is 9
 a(end-2:end) % is [8 9 10]

It works similar for cell arrays and struct-arrays.

Alhough subsref is quite powerful, and accepts for example the : colon oparator, it fails to process more complex stings, including end -operators.

This assignment is to create a function that accepts those more complex element definitions.

For example

 s.a.b(3).c{2}.d = 'a':'z';


 ans = 


subsrefbetter(s,substruct('.','a','.','b','()',{3},'.','c','{}',{2},'.','d','()',{'[1 end]'})) 

should return

 ans = 



should return

 ans =

The function subsrefbetter should accept both structures like created with substruct, and list of arguments like accepted by substruct.

That's all.

Solution Stats

50.0% Correct | 50.0% Incorrect
Last solution submitted on Aug 26, 2014
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!

Join the 15-year community celebration.

Play games and win prizes!

Learn more