필터 지우기
필터 지우기

How to place text in a single excel cell?

조회 수: 73 (최근 30일)
Robert
Robert 2019년 2월 21일
댓글: Robert 2019년 2월 21일
I'm running a series of analyses and exporting information to an Excel file to make it easier to summary, do additional analyses, share with collaborators, etc, and I have run into an issue that is probably very simple (so my aplogies if I have missed an obvious solution).
When I export the data to excel, I would like to export text to multiple cells. For example, if I were adding the value "Connecticut" to five cells in a single columns. The goal is to produce something like this:
I am using something similar to the following:
label = 'Connecticut';
label = repmat(label,5,1);
xlswrite(fid,label,sheet1,'A1');
which produces this:
so the script is importing the individual values (characters) into individual cells, rather than the entire row. Is there a simple way to change this?
Thanks,
Robert

채택된 답변

Walter Roberson
Walter Roberson 2019년 2월 21일
label = repmat( {label}, 5, 1)
  댓글 수: 3
Walter Roberson
Walter Roberson 2019년 2월 21일
T = 'hello';
label = repmat({T}, 5, 1);
%these next two can only work on MS Windows with Excel installed
xlswrite('testxx.xlsx', label)
xlswrite('testxc.csv', label)
%these will work on any release since tables were introduced
TT = array2table(label);
writetable( TT, 'testtx.xlsx', 'writevariablenames', false)
writetable( TT, 'testtc.csv', 'writevariablenames', false)
Robert
Robert 2019년 2월 21일
Well, I feel sheepish.
I initially tried this approach, and it didnt work.
Then I ran your script, and it worked fine.
It took me a while to realize I had misspelled a variable, which meant the { } were being applied to a variable that was not used in the repmat command.
Thanks for your patience and your code, it's much appreciated.
Cheers

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

추가 답변 (1개)

Robert
Robert 2019년 2월 21일
Update, I found a way to get the output, but its a bit clunky
Capture.PNG
It would be great to find a way that did not require a loop.

카테고리

Help CenterFile Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by