How to immediately pick an index from a result that is a matrix.

4 views (last 30 days)
I have a small issue which I stumble upon quite often.
Is it possible to immediately select a certain index if the result is a matrix.
For example, if I have a matrix stored under the Data of a uitable, and i want to retrieve it using get, and then take a certain index from it, my current method is like this:
para=get(handles.uitable6,'Data');
Calpha=para(5,1)
However, this requires for the creation of an additional matrix (in this case para), which might increase computing time for very late matrices. Is it possible to immediately pick one of the values from a matrix, thus preventing the creation of an additional matrix.
Thanks in advance,
Roy

Accepted Answer

Jan
Jan on 3 Jul 2012
This feature has been requested repeatedly, see: http://www.mathworks.com/matlabcentral/answers/1325#answer_1931
The line
para = get(handles.uitable6,'Data');
does not need a noticable amount of time, becauseit does not crate a new array and copy the data, but it is a "shared copy": only a new header for the variable is created, but the actual data are shared using a pointer to the same memory.
Therefore your posted code is efficient related to memory and processing time. The direct indexing would be "nicer" only.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!