How can I generate changing length of legend for a scatter graph generated in a while loop?

조회 수: 2 (최근 30일)
Hi everyone,
So i have the following code. where I would like to add legend for the scatter graph in the while loop. this is only a segment of the code. but basically the number of coloumns of M, M_2, M_3 is changing according to the user prompt. I want to add legend to the generated scatter plot, that varies in length ? (the variable f represents the user input)
M = [ 0.12 0.21 0.356 0.458 0.3659 0.2458 0.5412 0.324 0.2121];
M_2 = [0.35 0.56 0.12 0.321 0.987 0.88 0.44 0.66 0.23];
M_3 = [0.11 0.22 0.87 0.45 0.124 0.648 0.98 0.2 0.3];
cc = [-2 -1 0];
f = 7;
s = 17 - f;
while( s > 1)
s = s-1;
C = [M(s) M_2(s) M_3(s)];
hold on
scatter(cc,C);
hold on
end
h = lsline;
for k = 1:numel(h)
B = polyfit(h(k).XData, h(k).YData,1);
slope(k) = B(1);
intercept(k) = B(2);
end
Thank you for your help!

답변 (1개)

Bhaskar R
Bhaskar R 2019년 11월 12일
M = [ 0.12 0.21 0.356 0.458 0.3659 0.2458 0.5412 0.324 0.2121];
M_2 = [0.35 0.56 0.12 0.321 0.987 0.88 0.44 0.66 0.23];
M_3 = [0.11 0.22 0.87 0.45 0.124 0.648 0.98 0.2 0.3];
cc = [-2 -1 0];
f = 7;
s = 17 - f;
while( s > 1)
s = s-1;
C = [M(s) M_2(s) M_3(s)];
hold on
scatter(cc,C);
hold on
end
legend('show'); % add legend command
h = lsline;
for k = 1:numel(h)
B = polyfit(h(k).XData, h(k).YData,1);
slope(k) = B(1);
intercept(k) = B(2);
end
  댓글 수: 1
Lala0099
Lala0099 2019년 11월 12일
Thank you !
It works, but i want to give them uniques names. So instead of data, want it to be called channel 0 , channel 1 etc.

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

카테고리

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