MATLAB Answers

Matlab textArea automatic new line issue

조회 수: 22(최근 30일)
Leon 2021년 3월 14일
답변: Leon 2021년 3월 16일
I'm trying to generate a list of items. For each research cruise, its Year, Month, Day, Longitude, Latitude, etc. should all be in one row. Here is my code:
% generate the cruise list:
app.textArea.Value = '';
AA = [];
for i = 1:numel(cruiseList)
Ind1 = VAR(:,6) == cruiseList(i);
if sum(Ind1)>0
AA = [AA, 'Cruise #', num2str(cruiseList(i)), ', Year: ', ...
Sta{Ind1}.year, ', Month: ', Sta{Ind1}.month, '.'];
app.textArea.Value = AA;
Here is the problem. The generated information are not all in a row. Instead, they are break into many rows like the below:
Cruise #
, Year:
, Month:
Instead of the desired format of
Cruise #1, Year: 2015, Month: 10.
Why is Matlab automatically adding newlines? How should I fix this issue?
Many thanks.

채택된 답변

Leon 2021년 3월 16일
It turns out that the issue are the square brackets. Once I replace them with strcat, everything works perfectly now.
AA = [AA, 'Cruise #', num2str(cruiseList(i)), ', Year: ', ...
Sta{Ind1}.year, ', Month: ', Sta{Ind1}.month, '.'];
AA = strcat(AA, 'Cruise #', num2str(cruiseList(i)), ', Year: ', ...
Sta{Ind1}.year, ', Month: ', Sta{Ind1}.month, '.');

추가 답변(1개)

Asvin Kumar
Asvin Kumar 2021년 3월 16일
It's possible that the TextArea has WordWrap property set to 'on' by default.
If that doesn't solve it, you could try a couple of things:
  1. Set a breakpoint at the line where you set the TextArea's Value. Verify whether AA is a character vector without newlines.
  2. If you suspect that newlines are getting added later, try using sprintf to construct the string which you want to assign to TextArea. Example on using sprintf is here.
  댓글 수: 1
Leon 2021년 3월 16일
Many thanks!
As an update, this issue has been solved. I'll post the reply so that future users can get informed if they encounter a similar issue.

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




Community Treasure Hunt

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

Start Hunting!

Translated by