MATLAB: Creating Headers for xlswrite

headerxlswrite

Hello,
I am trying to create headers for data I am exporting from my code to excel. I want to have matlab print "ROI #1" in cell A2 of excel, "ROI #2" in A3, "ROI #3" in A4, etc. Here is what I have so far:
roi_count(1:(length(props{1})),1) = {'ROI #'};
roi_label(:,1) = num2cell(1:length(props{1}));
row_header = cellfun(@(x,y) [x y],roi_count,roi_label,'un',0);
range = 'A2'
xlswrite('advanced_test.xlsx',row_header,'Sheet1',range);
This gets close to what I want, however, the code prints "ROI #[]" in each cell within excel. I feel like I need to add a convert to string or something like that… unsure how to proceed. Please help!
Thanks 🙂

Best Answer

row_header = cellstr( num2str( (1:length(props{1})).', 'ROI #%d' ) ) .'
If you have R2017a or later you can use
row_header = cellstr( "ROI #" + (1:length(props{1})) );
If you have R2016b you can use
row_header = cellstr( string('ROI #') + (1:length(props{1})) );