Legend doesn't match my plot style

3 ビュー (過去 30 日間)
MOHAMED Camara
MOHAMED Camara 2019 年 12 月 3 日
コメント済み: Image Analyst 2019 年 12 月 3 日
I'm trying to match the legend with plot style, but it only shows the legend wrong.The problem is I have 3 different plot styles and different colors but the legend doesn't match with plot.
Here is my code:
figure;
hold all;
plot(max_time1,R1M1V1,'bs');
plot(max_time2,R2M1V1,'-.r');
plot(max_time3,R3M1V1,'--m');
title('Impedance Vs Time');
legend({'R1M1V1','R2M1V1','R3M1V1'});
hold off;
The output is below.
What am I doing wrong?
Thanks in advance

採用された回答

Image Analyst
Image Analyst 2019 年 12 月 3 日
編集済み: Image Analyst 2019 年 12 月 3 日
Are they vectors or matrices? Can you attach your data?
Anyway, put hold on after the first call to plot. That's the way I always do it, ,though hold all before might work
plot(max_time1,R1M1V1,'bs');
hold on;
plot(max_time2,R2M1V1,'-.r');
plot(max_time3,R3M1V1,'--m');
  2 件のコメント
MOHAMED Camara
MOHAMED Camara 2019 年 12 月 3 日
編集済み: Image Analyst 2019 年 12 月 3 日
The data are vectors. Here is the whole code for R1M1V1. R2M1V1& R3M1V1 are just a repetition.
n = 300; % average every n values
% read excel data
filename='V-CAMARA_M2';
sheet=15;
% voltage data
voltage1='B2:B30001'; % Cell location % For range use 'A2:B6'
voltage1_data=29671.2*xlsread(filename,sheet,voltage1);
max_voltage1 = arrayfun(@(i) mean(abs(voltage1_data(i:i+n-1))),1:n:length(voltage1_data)-n+1)';
voltage1maxmin = [max(max_voltage1) min(max_voltage1)];
mxI1 = voltage1maxmin(1);
mnI1 = voltage1maxmin(2);
I1p = linspace(mnI1, mxI1, 100);
% max_voltage1=2400*ones(100,1);
% current data
current1='F2:F30001'; % Cell location % For range use 'A2:B6'
current1_data=6*xlsread(filename,sheet,current1);
max_current1 = arrayfun(@(i) mean(abs(current1_data(i:i+n-1))),1:n:length(current1_data)-n+1)';
current1maxmin = [max(max_current1) min(max_current1)];
mxI01 = current1maxmin(1);
mnI01 = current1maxmin(2);
I01p = linspace(mnI01, mxI01, 100);
% time three data
time1='J2:J30001'; % Cell location % For range use 'A2:B6'
timedata1=xlsread(filename,sheet,time1);
max_time1 = arrayfun(@(i) max(abs(timedata1(i:i+n-1))),1:n:length(timedata1)-n+1)';
timemaxmin = [max(max_time1) min(max_time1)];
mxI001 = timemaxmin(1);
mnI001 = timemaxmin(2);
R1M1V1=max_voltage1/max_current1;
I001p = linspace(mnI001, mxI001, 100);
figure;
plot(max_time1,R1M1V1,'bs');
hold on;
plot(max_time2,R2M1V1,'-.r');
hold on;
plot(max_time3,R3M1V1,'--m');
hold on;
Image Analyst
Image Analyst 2019 年 12 月 3 日
Error using xlsread (line 136)
XLSREAD unable to open file 'V-CAMARA_M2'.
File 'V-CAMARA_M2' not found.
Error in test5 (line 15)
voltage1_data=29671.2*xlsread(filename,sheet,voltage1);
Still can't reproduce. Can you attach the workbook?

サインインしてコメントする。

その他の回答 (1 件)

Hank
Hank 2019 年 12 月 3 日
It looks like R1M1V1 is plotting three different curves. This could happen if max_time1 is a vector but R1M1V1 is a Nx3 matrix.
Plot will interpret each of the columns as a separate curve. Then, when you say legend('R1','R2','R3'), only the first three curves are labeled.
If all the data in R1M1V1 is the same type, they can be plotted in a single curve
plot(max_time, R1M1V1(:),'sb'); % use the 'vector(:)' syntax to force all the data into a column vector
% % do this for all the plots
  1 件のコメント
MOHAMED Camara
MOHAMED Camara 2019 年 12 月 3 日
R1M1VX is column vector 1x300

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLegend についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by