필터 지우기
필터 지우기

Creating Headers for xlswrite

조회 수: 5 (최근 30일)
itend
itend 2017년 9월 4일
댓글: itend 2017년 9월 4일
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 :)

채택된 답변

Walter Roberson
Walter Roberson 2017년 9월 4일
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})) );
  댓글 수: 1
itend
itend 2017년 9월 4일
Fantastic. Thank you for your help :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by