How do I extract data cursor structure elements to an array in MATLAB 7.7 (R2008b)?
    11 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
I want to save elements in a data cursor structure in a workspace into an array without using loop iterators (using a single command).
0 Kommentare
Antworten (2)
  Shigeru Sasao
    
 am 13 Jan. 2011
            plot(1:10);  
    %In the figure select say 3 data cursor points using DataCursor utility  
    % To select multiple points use ALT key  
    array_position = reshape([cursor_info.Position],2,3);
0 Kommentare
  Walter Roberson
      
      
 am 22 Jan. 2011
        Copied from my answer to the duplicate question #136:
YourCell = struct2cell(getCursorInfo(dcm_obj));
However, your question is not clear about whether you want to save all of the structure fields or only some of them, and is not clear about what kind of array you expect as a result. For example you might instead happen to need something more like
YourArray = cell2mat(arrayfun(@(S) S.Position,   getCursorInfo(dcm_obj), 'Uniform', 0));
The above code could be simplified and the arrayfun syntactic sugar hiding a loop could be removed if it was permissible to use two commands:
t = getCursorInfo(dcm_obj);
YourArray = vertcat(t.Position);
Please be advised that insisting that only one command be used can result in code that is hard to read and inefficient.
0 Kommentare
Siehe auch
Kategorien
				Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange
			
	Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


