Tuesday, November 25, 2014

Convert Excel row-column reference to A1 in MATLAB

I'm sure there are many of these snippets out there. Here is yet another one.
function [a1,aa] = rc2a1(row,col)
% RC2A1 convert row, column reference to A1 reference for excel
% A1 = RC2A1(ROW,COL) returns the equivalent reference as a string
% for the given row, ROW, and column, COL, numbers.
a1 = char(64+mod(col-1,26)+1);
xcol = ceil(col/26)-1;
if xcol>0
[~,aa] = rc2a1(row,xcol);
a1 = [aa,a1];
end
aa = a1;
a1 = [a1,int2str(row)];
end
view raw rc2a1.m hosted with ❤ by GitHub
>> rc2a1(23,196)
GN23
Enjoy. Please don't use it for evil.
Fork me on GitHub