How to create legend from cell array?

122 visualizaciones (últimos 30 días)
Heidi Mäkitalo
Heidi Mäkitalo el 14 de Jun. de 2019
Comentada: Heidi Mäkitalo el 14 de Jun. de 2019
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.

Respuesta aceptada

Stephen23
Stephen23 el 14 de Jun. de 2019
Editada: Stephen23 el 14 de Jun. de 2019
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:

Más respuestas (0)

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by