Error using legend MATLAB R2019b

조회 수: 6 (최근 30일)
Matthieu Assa
Matthieu Assa 2020년 3월 27일
댓글: Matthieu Assa 2020년 3월 27일
I get the following error while doing a plot in MATLAB 2019b on Windows 10:
"Error using legend (line 279) Element 1 is not a string scalar or character array. All elements of cell input must be string scalars or character arrays"
even though the arguments passed to the legend function are correct.
The error occurs only every third time or so with the exact same code... (The ylabel, xlabel and title functions work perfectly.) The code used was the following:
for i = 1:2
ylabel(obj.hAxis{i}, axisUnits)
xlabel(obj.hAxis{i}, 'Measurement Sample')
title(obj.hAxis{i}, [obj.signalId '-' sideArray{i}])
legend(obj.hAxis{i},[signalLabels], 'Location','EastOutside')
end
The following suggestion from another question: "opengl('save','software')" did not help.
Neither did storing the obj.hAxis{i} in a temporary variable and passing this temporary variable to the legend function.

채택된 답변

Peng Li
Peng Li 2020년 3월 27일
what is your signalLabels? Is that a cell or a string matrix?
  댓글 수: 3
Peng Li
Peng Li 2020년 3월 27일
Is that possible that you can show it's elements here? Or you can try make it string explicitely by string(signalLabels)?
Matthieu Assa
Matthieu Assa 2020년 3월 27일
Thanks a lot! making it a string explicitely solved the issue for me! (now it worked 40/40 times) :)
Although it still remains a bit confusing that with a cell it worked 24/40 times and failed 16/40 times... But now that I know how to solve the issue it doesn't matter anymore.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Legend에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by