Note that the xlcol and xlcoli are not a part of the loop, they are just there so the reader can identify with the variables.
xlswrite - not accepting stored string as valid 'A1' format for Excel
9 views (last 30 days)
Show older comments
I am currently trying to create a script that will output to Excel a series of 1000x8 matrices. So far my script looks like this, but it is not accepting xlcolo as a valid input and I can't figure out why. If there is an easier way to do this please help out!
xlcol = {'A3'; 'J3'; 'S3'};
xlcoli = {'A'; 'B'; 'C'; 'D'; 'E'; 'F'; 'G'; 'H'; 'I'; 'J'; 'K'; 'L'; 'M'; 'N'; 'O'; 'P'; 'Q'; 'R'; 'S'; 'T'; 'U'; 'V'; 'W'; 'X'; 'Y'; 'Z'};
%Output to Excel every 1000 trials
if rem(n,1000) == 0
a = n/1000;
if n > 3000
while a > 3
a = a - 3;
end
xlcolo = sprintf('%c%s',xlcoli(floor(n/3000)),xlcol(a));
else
xlcolo = xlcol(a);
end
xlswrite(spreadsheet, data, 'Martingale', xlcolo);
data = zeros(1,8);
end
I am aware that the code is not lasting beyond 78000 trials at the moment and will have to rectify that in the future. But for the time being I cannot work out why it thinks xlcolo is not a valid 'A1' format. I even tried displaying xlcolo in the command window before running xlswrite and it returned 'A3'.
Any help is greatly appreciated.
Regards,
Sam.
Accepted Answer
Sven
on 1 Mar 2012
G'day Mowgli,
The problem is that xcolo is a cell, but it's being referenced with parentheses:
xlcol = {'A3'; 'J3'; 'S3'};
xlcolo = xlcol(1);
The code above will return xlcolo(3) as a cell, but you want the contents of xlcolo(3) (ie, a string). Replace:
xlcolo = xlcol(a);
with:
xlcolo = xlcol{a};
and I think you'll be fine.
Note that your sprintf() function also needs to use braces {} to reference xcol otherwise sprintf will error saying "string expected"
More Answers (0)
See Also
Categories
Find more on Spreadsheets in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!