📄 exceltocoords.m
字号:
function coords = exceltocoords(excelrange)
% exceltocoords - converts MS-Excel notation into 1x4 double array
%
% FORMAT: coords = exceltocoords(range)
%
% Input fields:
%
% range string representing an excel range
%
% Output fields:
%
% coords 1x4 coords spec for range
%
% See also acsvread
% Version: v0.5c
% Build: 6120415
% Date: Dec-04 2006, 3:15 PM CET
% Author: Jochen Weber, Brain Innovation, B.V., Maastricht, NL
% URL/Info: http://wiki.brainvoyager.com/BVQXtools
% argument check
if nargin < 1 || ...
~ischar(excelrange)
error( ...
'BVQXtools:BadArgument', ...
'Bad or missing Excel notation.' ...
);
end
% split at colon
excelrange = splittocell(excelrange, ':', 1, 1);
if length(excelrange) < 2
excelrange{2} = excelrange{1};
end
% set defaults
ulx = 1;
uly = 1;
lrx = 256;
lry = 65535;
% get corner values
try
[ulx, uly] = i_splitexcelcoords(excelrange{1}, 0);
[lrx, lry] = i_splitexcelcoords(excelrange{2}, 1);
catch
coords = [ulx, uly, lrx, lry];
return;
end
if lrx < ulx
lrx = ulx;
end
if lry < uly
lry = uly;
end
coords = [ulx, uly, lrx, lry];
% internal function: convert 'B4' -> [2,4]
function [cx, cy] = i_splitexcelcoords(excelcoord, minmax)
% split coordinate to x and y
px = '';
py = '';
cc = 1;
cm = size(excelcoord, 2);
while cc <= cm && ...
excelcoord(cc) > 64
px = [px excelcoord(cc)];
cc = cc + 1;
end
while cc <= cm && ...
excelcoord(cc) > 47 && ...
excelcoord(cc) < 58
py = [py excelcoord(cc)];
cc = cc + 1;
end
% convert alpha to numeric
cm = size(px,2);
if cm == 0
if minmax == 0
cx = 1;
else
cx = 256;
end
else
if cm > 2
px = px(1:2);
end
px = lower(px);
px = px - 96; cx = px(1);
if size(px,2) > 1
cx = (cx*26) + px(2);
end
end
% check sizes for excel maximums (256,65535)
if size(py,2) == 0
if minmax == 0
cy = 1;
else
cy = 65535;
end
else
cy = str2double(py);
end
if cx > 256
cx = 256;
end
if cy > 65535
cy = 65535;
end
% end of function i_splitexcelcoords
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -