adding elements into a vector using MATLAB GUI
显示 更早的评论
I am new to matlab and I'm trying to make a progrem which gets parameters from the user(using gui)for x value and y value,puts them into 2 different vectors and when the user is done it uses plot to make a graph out of the two vectors.
here is what I tries to do:
function pushbutton1_Callback(hObject, eventdata, handles)
x=[];
y=[];
a=str2double(get(handles.edit1,'string'));
b=str2double(get(handles.edit2,'string'));
handles.x=[x a];
handles.y=[y b];
guidata(hObject, handles);
function Doit_Callback(hObject, eventdata, handles)
axes(handles.axes1)
handles.x;
handles.y;
handles.m=handles.x;
handles.n=handles.y;
plot(handles.m,handles.n);
guidata(hObject, handles);
function Doit_Callback(hObject, eventdata, handles)
axes(handles.axes1)
handles.x;
handles.y;
handles.m=handles.x;
handles.n=handles.y;
plot(handles.m,handles.n);
guidata(hObject, handles);
but the plot function won't work.I'm tring to get a and b from the edit text in the gui and put them into vector x and vector y,and when I'm done adding all the element I want I'm trying to use the full vectors in the Doit function. any help would be appreciated
2 个评论
Walter Roberson
2018-2-28
Are a and b intended to be vectors? Because str2double() only works for strings representing scalars. If this is the problem then str2num() works on strings representing scalars -- but is more fragile and less secure, since it is happy to accept input such as
delete('*.*')
and act on it...
elizabeth march
2018-2-28
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Workspace Variables and MAT Files 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!