Legend for matrix plot
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Björn Persson
el 2 de Sept. de 2016
Respondida: Adam
el 2 de Sept. de 2016
Hi. I have 3 matrixes. The first one contains measured frequencies:
freqs =
5 6 7
For each frequency I have x and y values:
x =
0.0116 0.0106 -0.0335
1.0986 1.0385 0.9020
2.0674 1.9955 1.9334
2.9450 3.0869 3.0334
4.0941 3.9551 4.0341
4.9456 4.9273 4.9743
6.0086 5.9592 6.0323
6.9813 7.0303 7.0465
7.9971 8.0223 8.0208
9.0282 8.9445 8.9044
10.0000 9.9224 10.0955
y =
-292 -286 -299
-283 -277 -295
-274 -267 -292
-266 -256 -285
-254 -245 -278
-244 -238 -272
-232 -227 -259
-224 -218 -249
-215 -210 -239
-208 -204 -231
-202 -199 -219
And to plot y vs x for each frequency i simply do:
p=plot(x,y)
which returns
p =
3x1 Line array:
Line
Line
Line
This plot is exactly as how like it. Now however. I can't put a legend here. For instance
legend('f1=5','f2=6','f3=7')
Returns the error:
Index exceeds matrix dimensions.
What can I do? It feels like I have tried everything..
3 comentarios
Adam
el 2 de Sept. de 2016
I will add my comment as an answer then in case it helps anyone else too.
Respuesta aceptada
Adam
el 2 de Sept. de 2016
This works fine for me. Do you have a variable with the name 'legend' that is hiding the function?
which -all legend
will show if this is the case. Then removing the variable will allow the function to be 'seen' again and all should work fine.
Try to make sure you never name variables after builtin functions. If you are unsure when naming a variable you can always use the 'which' command e.g.
which size
if you were considering to name a variable 'size'. then you will see this is a bad idea as it will show up a function of this name. Equally you should not name variables the same as your own functions for the same reason.
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Legend 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!