Legend for matrix plot

조회 수: 11 (최근 30일)
Björn Persson
Björn Persson 2016년 9월 2일
답변: Adam 2016년 9월 2일
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
Björn Persson
Björn Persson 2016년 9월 2일
It showed a variable, I removed it and now everything works. Thanks! I must have made a variable by mistake during debugging, and it caused me quite a lot of pain. Great that you could identify it!
Adam
Adam 2016년 9월 2일
I will add my comment as an answer then in case it helps anyone else too.

댓글을 달려면 로그인하십시오.

채택된 답변

Adam
Adam 2016년 9월 2일
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개)

카테고리

Help CenterFile Exchange에서 Legend에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by