Skip to content

Commit

Permalink
Progress
Browse files Browse the repository at this point in the history
  • Loading branch information
Frederik J. Simons committed Jun 12, 2015
1 parent 83e8879 commit aecc817
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 93 deletions.
13 changes: 4 additions & 9 deletions circ.m
Expand Up @@ -14,11 +14,11 @@
%
% OUTPUT:
%
% H Plot handle(s), to the circle and its origin
% H Plot handles to the circle and its origin
% cords Coordinates plotted
% theta Angles plotted, in radians
%
% Last modified by fjsimons-at-alum.mit.edu, 11/29/2010
% Last modified by fjsimons-at-alum.mit.edu, 12/01/2013

defval('radius',1)
defval('sectorwidth',2*pi)
Expand All @@ -40,9 +40,10 @@

x=x+origin(1);
y=y+origin(2);

hands=plot(x,y,'Color','k');

hold on

if nargin>2
hands=[hands ; plot(origin(1),origin(2),'k+')];
end
Expand All @@ -52,12 +53,6 @@
varns={hands,cords,theta};
varargout=varns(1:nargout);

%disp('set axis equal')

if nargin>=5
set(hands,varargin{1},varargin{2})
end




2 changes: 1 addition & 1 deletion fhanning.m
Expand Up @@ -13,7 +13,7 @@
% wl The left half of the window for lowpass
% wr The right half of the window for lowpass
%
% Last modified by fjsimons-at-alum.mit.edu, March 22nd, 2003
% Last modified by fjsimons-at-alum.mit.edu, 08/05/2014

if ~rem(n,2)
% Even length window
Expand Down
128 changes: 63 additions & 65 deletions getfieldr.m
Expand Up @@ -5,88 +5,85 @@
%
% GETFIELDR is an improvement on MATLAB's native GETFIELD function in that
% it will retrieve fields of any depth in a structure. The information
% retrieved from a structure can done several ways and depends on the
% nature of the "S" and "getFields" input varialbes and how many outputs
% can be retrieved from the structure in several ways depending on the
% nature of the "S" and "getFields" input variables and how many outputs
% are requested. Before retrieving fields, the function tests for
% uniqueness in the fieldnames of the structure because if one of the
% requested fields could refer to multiple fields within the structure,
% then function cannot know which of the fields was actually intended.
% then the function cannot know which of the fields was actually intended.
%
% INPUT:
%
% S Structure from which fields are to be retrieved
% 1. If a structure, fields are extracted directly
% 2. If a string, then a structure of that name is loaded
% S Structure from which fields are to be retrieved
% 1. If a structure, fields are extracted directly
% 2. If a string, then a structure of that name is loaded
% from the provided savefile "fname"
% getFields Fields to be retrieved
% 1. If empty/not provided, no fields are retrieved. Rather,
% the "allFields" and "allPaths" outputs are passed
% 2. If it is the string ':', then all field values of "S"
% getFields Fields to be retrieved
% 1. If empty/not provided, no fields are retrieved. Rather,
% the "allFields" and "allPaths" are output
% 2. If it is the string ':', then all field values of "S"
% are requested and outputted
% 3. For any other string or cell array of strings, those
% 3. For any other string or cell array of strings, those
% strings are treated as the requested fields of "S"
% fName A file where the structure may be stored
% fName A file where the structure may be stored
%
% OUTPUT:
%
% <none> Field values assigned directly in the calling workspace with
% variable names given by their in-structure fieldnames
% field1,... Field values passed out in the same order as "getFields"
% allFields Cell array of all fields
% allPaths Cell array of fieldpaths to the "allFields" fields
% <none> Field values assigned directly in the calling workspace with
% variable names given by their in-structure fieldnames
% field1,... Field values passed out in the same order as "getFields"
% allFields Cell array of all fields
% allPaths Cell array of fieldpaths to the "allFields" fields
%
% See also EVAL, FIELDNAMESR, NONUNIQUE, UNIQUE
%
% Last modified by gleggers-at-alumni.princeton.edu, 05/20/2014
% Last modified by fjsimons-at-alum.mit.edu, 10/07/2014

% If necessary, load the requested structure from its savefile
if ischar(S)
S = modload(fname,S);
S=modload(fname,S);
end

% Get the fieldpaths to all fields (terminal or otherwise)
allPaths = fieldnamesr(S,'full','prefix');

% Truncate those fieldpaths to just the fieldnames
for i = 1:length(allPaths)
pl = strfind(allPaths{i},'.');
allFields{i} = allPaths{i}(pl(end)+1:end);
for i=1:length(allPaths)
pl=strfind(allPaths{i},'.');
allFields{i}=allPaths{i}(pl(end)+1:end);
end

% If a "getFields" is not passed, pass out the listing of
% all terminal fields and their fieldpaths
if ~exist('getFields','var') || isempty(getFields)

varargout = {allFields allPaths'};
return

% If "getFields" is a string...
varargout={allFields allPaths'};
return

% If "getFields" is a string...
elseif ischar(getFields)
% If it is a ":", then all fields are being requested
if strcmp(getFields,':')
getFields=allFields;

% If it is a ":", then all fields are being requested
if strcmp(getFields,':')
getFields = allFields;

% Otherwise, assume just a single field is being requested,
% but place it in a cell array for later convenience
else
getFields = {getFields};
end
% Otherwise, assume just a single field is being requested,
% but place it in a cell array for later convenience
else
getFields={getFields};
end
end

% Get listing of all unique fieldnamess in the structure
uniqueFields = unique(unique(allFields));
uniqueFields=unique(unique(allFields));

% If the number of unique fieldnames is not equal to (actually, less than)
% the total number of fields, then the structure has duplicate fieldnames
% and this must be addressed
% If the number of unique fieldnames is any less than the total number of
% fields, then the structure has duplicate fieldnames, to be addressed
if length(uniqueFields) ~= length(allFields)
% Get complementary list of nonunique fieldnames
nonuniqueFields=nonunique(allFields);

% Get complementary list of nonunique fieldnames
nonuniqueFields = nonunique(allFields);

% If one of the requested fields is a nonunique field, the function
% cannot distinguish between the same-named fields, so throw an error
% If one of the requested fields is a nonunique field, the function
% cannot distinguish between the same-named fields, so throw an error
if any(ismember(getFields,nonuniqueFields))
error(['Certain requested fields correspond to duplicate field '...
'names in the structure. Please check and rename fields.'])
Expand All @@ -95,29 +92,30 @@
% the function will be fine, but throw a warning so the user is aware
else
warning(['The structure from which fields are being requested'...
'has duplicate field names, but none are among the'...
'requested fields.']);
'has duplicate field names, but none requested']);
end
end

% Depending on the number of output, the requested field values are
% Depending on the number of outputs, the requested field values are
% assigned differently
switch nargout

% For no requested output, assign requested field values directly into
% the calling workspace with fieldnames giving the new variable names
case 0
for i = 1:length(getFields)
assignin('caller',getFields{i},...
eval(allPaths{strcmp(getFields{i},allFields)}))
end

% For any other number of output, collect the field values into a
% cell array for output as a "varargout"
otherwise
for i = 1:length(getFields) % To nargout?
eval(sprintf('vars{i} = %s;',...
allPaths{strcmp(getFields{i},allFields)}));
end
varargout = vars(1:nargout);
end
% For no requested output, assign requested field values directly into
% the calling workspace with fieldnames giving the new variable names
case 0
for i=1:length(getFields)
assignin('caller',getFields{i},...
S.(getFields{i}))
% eval(allPaths{strcmp(getFields{i},allFields)}))
end

% For any other number of output, collect the field values into a
% cell array for output
otherwise
for i=1:length(getFields) % To nargout?
eval(sprintf('vars{i}=%s;',...
S.(getFields{i})));
% allPaths{strcmp(getFields{i},allFields)}));
end
% Output
varargout=vars(1:nargout);
end
19 changes: 10 additions & 9 deletions imagefnan.m
@@ -1,6 +1,6 @@
function varargout=imagefnan(c11,cmn,matrix,colmap,cax,nancol,invo,setnan)
% [h,sax]=IMAGEFNAN(c11,cmn,matrix,colmap,cax,nancol,invo,setnan)
% [h,sax]=IMAGEFNAN(matrix)
% [h,cax,Xrgb,c11,cmn]=IMAGEFNAN(c11,cmn,matrix,colmap,cax,nancol,invo,setnan)
% [h,cax,Xrgb,c11,cmn]=IMAGEFNAN(matrix)
%
% Uses IMAGE to plot data in a proper geographic reference
%
Expand All @@ -22,10 +22,12 @@
%
% h The axis handle to the image being plotted
% cax The color limits being used
% Xrgb The RGB matrix being plotted
% c11,cmn The physical coordinates
%
% See IMAGEF, IMAGEFDIR, JOINCOLMAP, ADDCB, HALVERANGE
%
% Last modified by fjsimons-at-alum.mit.edu, 03/18/2013
% Last modified by fjsimons-at-alum.mit.edu, 06/24/2014

if nargin==1
% Then the variable "c11" really is the variable "matrix"
Expand Down Expand Up @@ -86,11 +88,10 @@

X=reshape(X,[size(matrix),3]);

cm1=[c11(1) cmn(2)];
c1n=[cmn(1) c11(2)];

h=image([cm1(1) c1n(1)],[cm1(2) c1n(2)],flipdim(X,1));

% This is the call in case you want to substitute specific values
% Of course you could get X from get(gcf,'CData')
%h=image([c11(1) cmn(1)],[cmn(2) c11(2)],flipdim(X,1));
h=image([c11(1) cmn(1)],[c11(2) cmn(2)],X);
axis xy image

if nargin>4
Expand All @@ -100,5 +101,5 @@
end

% Prepare output
varns={h,cax};
varns={h,cax,X,c11,cmn};
varargout=varns(1:nargout);
4 changes: 2 additions & 2 deletions ls2cell.m
Expand Up @@ -16,7 +16,7 @@
%
% NOTE: Remember that directories end with a "filesep" and files do not.
% So if you want a fullpath and submit a directory, it needs to end in
% filesep to be correct.
% filesep to be correct. Otherwise, you get the "non-exist" error.
%
% EXAMPLE:
%
Expand All @@ -26,7 +26,7 @@
% names=ls2cell([pwd '/*SAC'],1)
%
% Last modified by fjsimons-at-alum.mit.edu, 09/10/2014
% Last modified by charig-at-princeton.edu, 09/10/2014
% Last modified by charig-at-princeton.edu, 09/23/2014

defval('fullpath',0);

Expand Down
19 changes: 12 additions & 7 deletions nonunique.m
Expand Up @@ -3,16 +3,16 @@
% [C,AI] = NONUNIQUE(A,'sorted')
% [C,AI] = NONUNIQUE(A,'stable')
%
% A complement to MATLAB's UNIQUE function. For a given vector or cell
% A complement to MATLAB's UNIQUE function. For a given matrix or cell
% array of strings, this function finds its nonunique members, including
% the first occurence of each nonunique element (which, under a strict
% definition of nonuniqueness, might be exluded), as well as an index
% vector to input "A" such that C = A(IA). This function mirrors UNIQUE
% in terms of sorted/stable output.
% in terms of sorted/stable output and the output's orientation.
%
% INPUT:
%
% A Vector/cell array from which to find nonunique members
% A Matrix/cell array from which to find nonunique members
% varargin Control on how the output nonunique values are sorted
% <empty>: Nonunique values are sorted
% 'sorted': Same as the <empty>
Expand All @@ -26,10 +26,15 @@
%
% See also ISMEMBER, SORT, UNIQUE
%
% Last modified by gleggers-at-alumni.princeton.edu, 05/20/2014
% Last modified by gleggers-at-alumni.princeton.edu, 05/21/2014

% If "A" is a matrix, vectorize it and find nonunique values of the new "A"
if ~any(size(A) == 1)
A = A(:);
end

% Make an index vector for all the elements of "A"
indA = 1:length(A);
indA = (1:length(A))';

% Get the unique values of "A" and their linear indices
[uA,iuA] = unique(A);
Expand All @@ -48,7 +53,7 @@
% Combine the previous indices of nonunique values with the indices of
% unique values which are repeated, and use this new index array to find
% the loosely defined nonunique values
IA = sort([inuA(:) ; inboth(:)]);
IA = sort([inuA(:); inboth(:)]);
C = A(IA);

% To match the UNIQUE function, if the 'sorted' flag or no flag is given,
Expand All @@ -61,4 +66,4 @@
% be done because the nonunique values are already not sorted)
elseif ~strcmp(varargin{1},'stable')
error('Variable input ''%s'' was not of the proper form',varargin{1})
end
end
4 changes: 4 additions & 0 deletions renamefield.m
Expand Up @@ -11,6 +11,10 @@
%
% S The new structure array
%
% SEE ALSO:
%
% STRUCT2STR
%
% Last modified by fjsimons-at-alum.mit.edu, 05/29/2013

[S.(name2)]=S.(name1);
Expand Down

0 comments on commit aecc817

Please sign in to comment.