Clear Filters
Clear Filters

Creating Headers for xlswrite

5 views (last 30 days)
itend
itend on 4 Sep 2017
Commented: itend on 4 Sep 2017
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 :)

Accepted Answer

Walter Roberson
Walter Roberson on 4 Sep 2017
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})) );

More Answers (0)

Categories

Find more on Characters and Strings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!