Filter löschen
Filter löschen

How to create legend from cell array?

92 Ansichten (letzte 30 Tage)
Heidi Mäkitalo
Heidi Mäkitalo am 14 Jun. 2019
Kommentiert: Heidi Mäkitalo am 14 Jun. 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.

Akzeptierte Antwort

Stephen23
Stephen23 am 14 Jun. 2019
Bearbeitet: Stephen23 am 14 Jun. 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:

Weitere Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by