plotting multiple variables in a listbox
이전 댓글 표시
Good Morning, I am trying to plot all variables selected in a listbox in a matlab gui. I seem to be overwriting the variables when plotting and only plotting the last one even when using the hold on command inside the loop. I also cannot figure out how to add a legend to the plot which corresponds to the variable selected in the listbox.
Any suggestions?
Thanks so much.
%Setting up string and value for desired parameters
Variable_Name = get(handles.Parameter_Listbox,'String');
Index = get(handles.Parameter_Listbox,'Value');
%Setting results plot
axes(handles.Plot)
%Creating loop for parameters choosen
for i=1:length(Index)
Parameter(:,i)=Data(:,Index(i))
end
[j,k]=size(Parameter);
for p=1:k
plot(Data(:,2),Parameter(:,k));
hold on
legend(Variable_Name(k));
hold on
end
채택된 답변
추가 답변 (1개)
Michael Haderlein
2014년 8월 18일
편집: Michael Haderlein
2014년 8월 18일
You only plot the last Parameter, you need to change the line
plot(Data(:,2),Parameter(:,k));
to
plot(Data(:,2),Parameter(:,p));
The same with the legend, too.
댓글 수: 3
Melissa
2014년 8월 18일
Michael Haderlein
2014년 8월 18일
편집: Michael Haderlein
2014년 8월 18일
Sorry, my comment on the legend was wrong. You overwrite the legend in every iteration. Put the legend command below the loop and write
legend(Variable_Name(Index))
Michael Haderlein
2014년 8월 18일
Anyway, Jan Simon's answer is better as he plots everything without the loop - just follow his answer.
카테고리
도움말 센터 및 File Exchange에서 Legend에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!