plotting two curve in one axes

Hi all; I have to plot two functions in same axes these functions in two different pushbutton functions, the code so far is as follow:
- function pushbutton1_Callback(hObject, eventdata, handles)
x = [31 32 32 33 34 35 35 37 37]; % data 1
y = [0 3 11 29 53 80 98 126 150]; % maximum power
plot(handles.axes,x,y)
- function pushbutton2_Callback(hObject, eventdata, handles)
x = [31 32 32 33 34 35 35 37 37]; % data 1
y1=y*0.7; % actual power
plot(handles.axes,x,y1)
the problem that i am facing is when plotting the second function the first is disappear. how to overcome this issue ?? please help and advice.
Sam

 采纳的回答

by using (handles.axes) so need to hold on this axes, if using hold on only its not working it will work only with plot(x,y) not with plot(handles.axes,x,y) the code should be as follow:
- function pushbutton1_Callback(hObject, eventdata, handles)
x = [31 32 32 33 34 35 35 37 37]; % data 1
y = [0 3 11 29 53 80 98 126 150]; % maximum power
plot(handles.axes,x,y)
- function pushbutton2_Callback(hObject, eventdata, handles)
x = [31 32 32 33 34 35 35 37 37]; % data 1
y1=y*0.7; % actual power
hold(handles.axes,'on')
plot(handles.axes,x,y1)

更多回答(2 个)

hold on;
plot(handles.axes,x,y1)

10 个评论

thanks for ur suggestion.
but I have tried this way, but it get the same results. only one curve will be showing. so how to keep both curves ??
what is the name of your axes object, by default it's axes1, have you changed it? if not then
hold on;
plot(handles.axes1,x,y1)
have you any error message?
i am not getting any error, it just plot one function in the axes (not two curves) so how to get both plotted on one axes
post the full code of your function (the one involved with plot)
- function pushbutton1_Callback(hObject, eventdata, handles)
[num,T,vT] = xlsread('Excel 1.xlsx','Sheet1');
x = num(:,1); % Time column
y = num(:,4); % maximum power column
plot(handles.axes8,x,y,'-ob',...
'LineWidth',1,...
'MarkerEdgeColor','b',...
'MarkerFaceColor','b',...
'MarkerSize',6)
datetick(handles.axes8,'x' ,15)
- function pushbutton2_Callback(hObject, eventdata, handles)
d= str2double(get(handles.edit51,'string')); %derating factor
y1= y*d; %actual power
hold on;
plot(handles.axes8,x,y1,'-or',...
'LineWidth',1,...
'MarkerEdgeColor','r',...
'MarkerFaceColor','r',...
'MarkerSize',6)
datetick(handles.axes8,'x' ,15)
this is the full code, but when I plot the actual power (the second function the) the first curve disappear.
You said a full code. What are y and x in function 2. Not defined
(x) and (y) is data reading from the excel file, where x is the time and y is the maximum power. so its plot as a power against the time, so the user might define the de-rating factor to plot the actual power. thanks for your time is replying here
You said it s a full code but in your second function there is no xlsread
I just remove it cause its not the main of what i am asking for. when I am using the (hold on) the first function is disappear, so I wounder how to overcome this issue ?
to find the problem, it's usefull to read the full code, at least of functions that are involved. Because there is no problem with
hold on;
plot(handles.axes,x,y1)
I did it and it works

请先登录,再进行评论。

Jürgen
Jürgen 2012-9-18

0 个投票

use the hold function
hold on for example will help
regardsJ

类别

帮助中心File Exchange 中查找有关 Data Exploration 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by