PDA

查看完整版本 : [求助]edittext的数值怎样传递入公式运算?


yangn2003
2008-07-10, 19:59
我想通过edittext,让用户输入一个数值w,坐标轴横轴为se,纵轴为sa, w=se/sa,绘制出坐标图,edittext命名为ex73_etext, 按钮命名为ex_plot, 用户输入数值后按按钮显示图形,可是w的值好像总是不能顺利传进计算式,图形显示不出来,请问问题出在哪里?


function ex73_etext_Callback(hObject, eventdata, handles)
% hObject handle to ex73_etext (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of ex73_etext as text
% str2double(get(hObject,'String')) returns contents of ex73_etext as a double


% --- Executes during object creation, after setting all properties.
function ex73_etext_CreateFcn(hObject, eventdata, handles)
% hObject handle to ex73_etext (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in ex73_plot.
function ex73_plot_Callback(hObject, eventdata, handles)
% hObject handle to ex73_plot (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
flag=get(handles.ex73_etext,'Value'); %get the value of the edittext
w=[str2double(flag),'Value'];
t=0:0.001:2*pi; %define the array t
se=1;

sa=w*(se*t); 问题所在


axes(handles.ex73_axes) %claim the graph drawed on the ex71_axes
plot(se*t,sa)


错误显示:
Warning: Out of range or non-integer values truncated during conversion to character.
> In ex73>ex73_plot_Callback at 106
In gui_mainfcn at 75
In ex73 at 42
??? Error using ==> mtimes
Inner matrix dimensions must agree.

Error in ==> ex73>ex73_plot_Callback at 110
sa=w*(se*t);

Error in ==> gui_mainfcn at 75
feval(varargin{:});

Error in ==> ex73 at 42
gui_mainfcn(gui_State, varargin{:});

??? Error using ==> ex73('ex73_plot_Callback',gcbo,[],guidata(gcbo))
Error using ==> mtimes
Inner matrix dimensions must agree.

??? Error while evaluating uicontrol Callback