필터 지우기
필터 지우기

How to create legend from cell array?

조회 수: 92 (최근 30일)
Heidi Mäkitalo
Heidi Mäkitalo 2019년 6월 14일
댓글: Heidi Mäkitalo 2019년 6월 14일
I have the following cell array:
>> itm{2}
ans =
'0,31:1.03 SPEED MEASURED 1 [rpm]'
'0,32:1.03 SPEED MEASURED 1 [rpm]'
'0,33:1.03 SPEED MEASURED 1 [rpm]'
'0,34:1.03 SPEED MEASURED 1 [rpm]'
'0,31:1.04 MOTOR SPEED [rpm]'
'0,32:1.04 MOTOR SPEED [rpm]'
'0,33:1.04 MOTOR SPEED [rpm]'
'0,34:1.04 MOTOR SPEED [rpm]'
'0,31:1.08 MOTOR TORQUE [%]'
'0,32:1.08 MOTOR TORQUE [%]'
'0,33:1.08 MOTOR TORQUE [%]'
'0,34:1.08 MOTOR TORQUE [%]'
'0,31:25.04 TORQUE REF B [%]'
'0,32:25.04 TORQUE REF B [%]'
'0,33:25.04 TORQUE REF B [%]'
'0,34:25.04 TORQUE REF B [%]'
What I want is to have four consecutive rows of the cell array as a legend for one figure. For example, Figure 1 would have the following legend:
'0,31:1.03 SPEED MEASURED 1 [rpm]'
'0,32:1.03 SPEED MEASURED 1 [rpm]'
'0,33:1.03 SPEED MEASURED 1 [rpm]'
'0,34:1.03 SPEED MEASURED 1 [rpm]'
Then Figure 2 would have the next four rows and so on.
I've tried this to make a legend for Figure 1:
legend(itm{2}(1,:), itm{2}(2,:), itm{2}(3,:), itm{2}(4,:));
But that only adds the fourth row into the legend, not all four of them. So clearly that's wrong.

채택된 답변

Stephen23
Stephen23 2019년 6월 14일
편집: Stephen23 2019년 6월 14일
Simply using one cell array:
legend(itm{2}(1:4))
or using your approach of separate input arguments (character vectors):
legend(itm{2}{1},itm{2}{2},itm{2}{3},itm{2}{4})
Read more:

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by