Effacer les filtres
Effacer les filtres

How to create legend from cell array?

92 vues (au cours des 30 derniers jours)
Heidi Mäkitalo
Heidi Mäkitalo le 14 Juin 2019
Commenté : Heidi Mäkitalo le 14 Juin 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.

Réponse acceptée

Stephen23
Stephen23 le 14 Juin 2019
Modifié(e) : Stephen23 le 14 Juin 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:

Plus de réponses (0)

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by