How to create legend from cell array?

92 次查看(过去 30 天)
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