legend imformation is incorrect
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
Please I am plotting the data attached with just the simple code below but the legends repeats the first color for the second plot.

plot(DownExtraction','m');
hold on
plot(Upperextraction','b');
xlabel('Wavelength');
ylabel('Intensity');
legend('Down Extraction','Upper Extraction');
title('FEMD Dual Position Extraction of DS');
Please your help wil be appreciated.
채택된 답변
Star Strider
2019년 9월 29일
You must be plotting something else that is not in the code you posted or the data you attached.
This code:
D1 = load('Upper extraction.mat');
UpperExtraction = D1.DS_DATA_ODU;
D2 = load('Down Extraction.mat');
DownExtraction = D2.DS_DATA_ODD;
plot(DownExtraction','m');
hold on
plot(UpperExtraction','b');
xlabel('Wavelength');
ylabel('Intensity');
legend('Down Extraction','Upper Extraction');
title('FEMD Dual Position Extraction of DS');
produces this plot:

That appears correct to me.
Note that the line at zero intensity does not appear.
The problem may be that you are plotting something else afterwards, with the hold state still on.
Try this instead:
figure
plot(DownExtraction','m');
hold on
plot(UpperExtraction','b');
hold off % <— Toggle ‘hold’ Off Here
xlabel('Wavelength');
ylabel('Intensity');
legend('Down Extraction','Upper Extraction');
title('FEMD Dual Position Extraction of DS');
Experiment to get the result you want.
댓글 수: 11
Yussif M. Awelisah
2019년 9월 30일
this really helped im sincerely grateful.
Yussif M. Awelisah
2019년 9월 30일
The first figure I sent is the correct figure. is there a way I can copy the legend of the second figure you sent into the first figure.
As always, my pleasure!
‘The first figure I sent is the correct figure. is there a way I can copy the legend of the second figure you sent into the first figure.’
I am not quite certain what you want.
Try this:
figure
hp{1} = plot(DownExtraction','m');
hold on
hp{2} = plot(UpperExtraction','b');
hold off % <— Toggle ‘hold’ Off Here
xlabel('Wavelength');
ylabel('Intensity');
legend([hp{:}], 'Down Extraction','Upper Extraction');
title('FEMD Dual Position Extraction of DS');
You can then plot anything else you want. Only the ‘hp’ plot colours will be present in the legend.
Experiment to get the result you want.
The code I posted works for me (in R20198b). I can’t tell what is throwing the horzcat error.
Try this slightly edited version:
figure
hp1 = plot(DownExtraction','m');
hold on
hp2 = plot(UpperExtraction','b');
hold off % <— Toggle ‘hold’ Off Here
xlabel('Wavelength');
ylabel('Intensity');
legend([hp1 hp2], 'Down Extraction','Upper Extraction');
title('FEMD Dual Position Extraction of DS');
Yussif M. Awelisah
2019년 9월 30일
Please Im grateful. As far it works on your version of your matlab.Its ok. I will get that version. I just tried but same error still occured. Im using (R2015a)
Please can attach me the figure that worked on your version.
thank you.
Star Strider
2019년 9월 30일
As always, my pleasure.
What line is throwing the error? What does it refer to? (Please include all the red text from your Command Window.)
‘Please can attach me the figure that worked on your version.’
My code should work in R2015a. It might be worthwhile to attach all the data that you used to plot all your data, and the code you wrote to plot them. (I no longer have access to R2015a, so I cannot test my code with it.)
Yussif M. Awelisah
2019년 10월 7일
sorry for the delay. Unfortunaately I left the lab for few days.
I am grateful for your support and concern.
The data for the plot I first posted in my question is the data I am working with at the moment in my current research. The data you used in your answer is the original data but contains error of noise and scattering component as you can see in your plot.
Literally what I want to achieve is the plot of the initial data I posted in the question with it correct legend.
Attached is the data for the original data and the current data Im trying to plot.
The down Extraction and Upper extraction is the current data Im trying to plot. And the remaining two DS data is the original data as used in your plot.
I will be humbled for your support.
It worked fine for me in R2015a using the commands:
D1 = load('Upper extraction.mat');
UpperExtraction = D1.DS_DATA_ODU;
D2 = load('Down Extraction.mat');
DownExtraction = D2.DS_DATA_ODD;
>> figure
hp{1} = plot(DownExtraction','m');
hold on
>> hp{2} = plot(UpperExtraction','b');
>> hold off % <— Toggle ‘hold’ Off Here
xlabel('Wavelength');
ylabel('Intensity');
legend([hp{:}], 'Down Extraction','Upper Extraction');
Walter Roberson
2019년 10월 7일
But literally that is the plot for the original data( DS_DATA_ODU and DS_DATA_ODD).
The data i want to plot is the data attached.
The code I provided reads from the Upper and Down .mat files and plots their contents. It is not reading from DS_DATA_ODD2.mat or DS_DATA_ODU2.mat . The variables it loads are the only things in the Upper and Down .mat files, so the code does plot what you ask to be plotted.
If you want to plot additional lines, then record their handles and pass the appropriate handles to legend() .
It looks likely to me that you are plotting four lines, with the first two being the same color and the same place as each other, thus giving the impression that only one line has been plotted.
I am grateful for kindness and support.
I hope you can try plotting the attached data. May be the previous data was same as the original data.
I used the code below but got the attached error.
figure
hp{1} = plot(Down','m');
hold on
hp{2} = plot(Upper','b');
hold off % <— Toggle ‘hold’ Off Here
xlabel('Wavelength');
ylabel('Intensity');
legend([hp{:}], 'Down Extraction','Upper Extraction');
title('FEMD Dual Position Extraction of DS');
Error using horzcat
Dimensions of matrices being concatenated are not consistent.

@Walter — Thank you!
@Yussif Moro Awelisah — Your data are confusing and not well documented.
This worked for me when I tried it (with the ‘Down.mat’ and ‘Upper.mat’ files attached to your latest Comment):
figure
hp1 = plot(Down','m');
hold on
hp2 = plot(Upper','b');
hold off % <— Toggle ‘hold’ Off Here
xlabel('Wavelength');
ylabel('Intensity');
legend([hp1(1),hp2(1)], 'Down Extraction','Upper Extraction');
title('FEMD Dual Position Extraction of DS');
You need to experiment with the ‘hp’ handles (as I have called them here) to be sure they correspond with the data you are plotting. I have no idea what they are or how you calculated them, so I just experimented until I got them to work. If they are the reverse of what they should be, reverse the order of the ‘hp’ elements in the legend handle vector (between the square brackets []).
Note that ‘Down’ is a (6x500) double matrix, and ‘Upper’ is a (4x500) double matrix. You appear to be plotting the same data (or approximately the same data) several times.
추가 답변 (1개)
Yussif M. Awelisah
2019년 10월 8일
0 개 추천
@Star Strider
@Walter Roberson
I am sincerely grateful. This worked for me and I am sincerely grateful for your loyalty and kindness.
댓글 수: 1
Star Strider
2019년 10월 8일
As always, our pleasure.
카테고리
도움말 센터 및 File Exchange에서 Legend에 대해 자세히 알아보기
태그
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
