function [Kr,Kc] = nodesub(R,C)
% NODESUB Grid node subscripts
%
%  [Kr,Kc] = NODENUM(R,C) where R and C are the dimensions (rows,
%  columns) of a grid, and Kr,Kc contain the subscripts for each
%  node's location

    
% Jerod Weinman
% jerod@acm.org
  
%	$Id: nodesub.m 1 2009-05-07 13:41:00Z weinman $
 
% Jerod Weinman
% jerod@acm.org
% Copyright 2004, 2008, 2009
 
%    This file is part of Matlab GridCRF.
%
%    Matlab GridCRF is free software: you can redistribute it and/or modify
%    it under the terms of the GNU General Public License as published by
%    the Free Software Foundation, either version 3 of the License, or
%    (at your option) any later version.
%
%    Matlab GridCRF is distributed in the hope that it will be useful,
%    but WITHOUT ANY WARRANTY; without even the implied warranty of
%    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%    GNU General Public License for more details.
%
%    You should have received a copy of the GNU General Public License
%    along with Matlab GridCRF.  If not, see <http://www.gnu.org/licenses/>.
    
  if nargin==1
	
	if length(R)<2
	  error('Requires two arguments or vector');
	end;
	
	C = R(2);
	R = R(1);

  end;
  
  [Kr,Kc] = ind2sub([R C], 1:(R*C));
