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

Lala0099

### Lala0099 (view profile)

님이 질문을 제출함. 12 Nov 2019 13:13
최근 활동 Lala0099

### Lala0099 (view profile)

님이 댓글을 추가함. 12 Nov 2019 13:53
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

로그인 to comment.

## 답변 수: 1

님의 답변 12 Nov 2019 13:30

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

Lala0099

### Lala0099 (view profile)

12 Nov 2019 13:53
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.

로그인 to comment.