specifying cells in xlswrite with excel syntax

1 view (last 30 days)
Hi, Is it possible to call excel cells as:
xlswrite('C:\Users\mpaulosk\Desktop\Folder\File.xls',{new},'Batch Data', cell)
where cell = (m, anew) and m and anew are updated in a for loop?
[~, ~, read] = xlsread('C:\Users\mpaulosk\Desktop\folder\prelim_gui.xls','Sheet1');
[~, ~, read2write] = xlsread('C:\Users\mpaulosk\Desktop\folder\file.xls','Batch Data');
paramtext = vertcat(read(1:7,1));
file2write = (read2write);
b = 350;
d = 375;
n = 1 ;
m = 1;
a = 10;
numcol = size (read2write)
for ii = 1:84
a = a + 1
if cellfun(@isnan,read2write(2,a)) == 1
store = read2write(2,a)
newa = a
break
elseif cellfun(@isnan,read2write(2,a)) == 0
a = a
else
error = uicontrol('Style', 'text', 'String', 'Error: Unable to locate empty column')
end
end
for ii = 1:6
b = b - 50
d = d-50
n = n + 1
m = m + 1
tparamnew = paramtext(n,1)
tparamnew = uicontrol('Style','text','String', tparamnew, ...
'Position',[100 b 150 40])
eparamnew = uicontrol('Style', 'edit', ...
'Position',[350 d 100 20], 'Callback', @write)
end
%cell = (m, newa)
function write(hObject,event)
current_string = get(hObject,'String');
new = str2num(current_string)
xlswrite('C:\Users\mpaulosk\Desktop\Quartette\Levo_EE.xls',{new},'Batch Data', cell)
tl;dr I need matlab to recognize something like (4,18) instead of D18
Thanks!

Answers (2)

Image Analyst
Image Analyst on 31 May 2013
cell is the name of a built-in function so don't use it for your variable. Call it cellReference instead. cellReference has to be a string. According to the help:
xlRange — Rectangular portion of the worksheet to writestring
Rectangular portion of the worksheet to write, specified asa string.
Specify xlRange using the syntax 'C1:C2',where C1 and C2 are two opposingcorners that define the region to write. For example, 'D2:H4' representsthe 3-by-5 rectangular region between the two corners D2 and H4 onthe worksheet. The xlRange input is not case sensitive,and uses Excel A1 reference style (see Excel help). xlswrite doesnot recognize named ranges.
If you do not specify sheet, then xlRange mustinclude both corners and a colon character, even for a single cell(such as 'D2:D2'). Otherwise, xlswrite interpretsthe input as a worksheet name (such as 'D2').
If you specify sheet, then xlRange canspecify only the first cell (such as 'D2'). xlswrite writesinput array A beginning at this cell.
If xlRange is larger than the sizeof input array A, Excel software fills theremainder of the region with #N/A. If xlRange issmaller than the size of A, then xlswrite writesonly the subset that fits into xlRange to the file.

Meaghan
Meaghan on 3 Jun 2013
Edited: Meaghan on 3 Jun 2013
Thanks! I changed the name, but now is there a way to get around calling it C1:C2, etc.? My function calculates cell numbers based on their place in a matrix and I can't find a way to conver that to excel format.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!