Color of legend doesnt fit the plot

조회 수: 2 (최근 30일)
Tatjana Mü
Tatjana Mü 2022년 5월 2일
댓글: Tatjana Mü 2022년 5월 3일
Dear all,
I know this question was asked thousand times before. But none of the solutions are working for me. I have a loop to import several files. Afterwards I do some calculations and want to plot them (for all the files in one plot). Therefore I use following code:
directory_name=uigetdir('','Ordner mit Messungen auswählen');
[nur_file_name,pfad]=uigetfile({'*.csv','csv-files (*.csv)';'*.*','all Files'},...
'Die csv-Files der Proben oeffnen (probe_001.csv=',[directory_name '/'], 'Multiselect', 'on');
nur_file_name=cellstr(nur_file_name);
nur_file_name=sort(nur_file_name);
filename=strcat(pfad,nur_file_name);
anzahl_files=size(filename,2);
for xy=1:anzahl_files
fid_in=fopen(char(filename(xy)),'r');
%Calculations...
%Plot Sr ratio for all files:
[NumRows1 NumCols1]=size(Ratio);
figure(1)
title('Proben 87Sr/86Sr');
xlabel('Partikel');
ylabel('87Sr/86Sr');
for p=1:anzahl_files
h(p)= scatter(1:NumRows1, Ratio(:,1));
legendtext{p} = filename_s(1,p);
hold on
end
legend(h, legendtext)
end
I am sorry to ask this again. But I dont find my mistake. It plots perfectly, the probleme is just that the colours are not matching. I appreciate any help.

답변 (1개)

Image Analyst
Image Analyst 2022년 5월 2일
Why are you plotting the same data (the first column of Ratio) every iteration? If you do that, all the markers are on top of each other so that only the last set will show up. Did you mean to scatter different columns of Ratio like this:
h(p)= scatter(1:NumRows1, Ratio(:, p));
  댓글 수: 9
Image Analyst
Image Analyst 2022년 5월 3일
Your indenting is all messed up. Looks like you have a for loop with 5 other for loops inside of it. Is that what you want?
Type control-a (to select all) then control-i (to fix the indenting).
Tatjana Mü
Tatjana Mü 2022년 5월 3일
@Image Analyst I am sorry for the messed up part. I am honestly kind of new in programming. I am mostly if it works like I want it to work. And mostly it just works like I want to have it, if I use a lot of loops.
Thank you for explaining the control a/ control i to me.
Do you maybe know why my legend is not working?

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

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by