| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3909 人关注过本帖
标题:MATLAB中曲柄摇杆机构动画仿真分析,其中运行出现错误
只看楼主 加入收藏
施杰越
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2018-6-18
收藏
 问题点数:0 回复次数:0 
MATLAB中曲柄摇杆机构动画仿真分析,其中运行出现错误
function varargout = xianshi(varargin)
% XIANSHI MATLAB code for xianshi.fig
%      XIANSHI, by itself, creates a new XIANSHI or raises the existing
%      singleton*.
%
%      H = XIANSHI returns the handle to a new XIANSHI or the handle to
%      the existing singleton*.
%
%      XIANSHI('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in XIANSHI.M with the given input arguments.
%
%      XIANSHI('Property','Value',...) creates a new XIANSHI or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before xianshi_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to xianshi_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help xianshi

% Last Modified by GUIDE v2.5 15-Jun-2018 15:29:20

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @xianshi_OpeningFcn, ...
                   'gui_OutputFcn',  @xianshi_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before xianshi is made visible.
function xianshi_OpeningFcn(hObject, ~, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to xianshi (see VARARGIN)

% Choose default command line output for xianshi
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes xianshi wait for user response (see UIRESUME)
% uiwait(handles.figure1);
set(gcf,'name','曲柄摇杆机构运动分析及动画显示')
hh1=handles.axes1;cla(hh1)
set(hh1,'PlotBoxAspectRatio',[1 1 1],'XTick',[],'YTick',[],'box','on','Visible','off')
hh2=handles.axes2;
set(hh2,'box','on','Visible','off','XTick',[])
hh3=handles.axes3;
set(hh3,'box','on','Visible','off','XTick',[])
hh4=handles.axes4;
set(hh4,'box','on','Visible','off')


% --- Outputs from this function are returned to the command line.
function varargout = xianshi_OutputFcn(~, ~, handles)
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(~, ~, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


ax=evalin('base','ax');ay=evalin('base','ay');
bx=evalin('base','bx');by=evalin('base','by');
cx=evalin('base','cx');cy=evalin('base','cy');
dx=evalin('base','dx');dy=evalin('base','dy');
theta3= evalin('base','theta3');theta2=evalin('base','theta2');
theta1= evalin('base','theta1');omiga2=evalin('base','omiga2');
omiga3= evalin('base','omiga3');alph3=evalin('base','alph3');
alph2=evalin('base','alph2');
c=evalin('base','c');
hh1=handles.axes1;
set(hh1,'xlim',[-max(abs(bx))-2,max([abs(cx),dx])+10],'ylim',...
    [-max([abs(cy),abs(by),dy])-2,max([abs(cy),abs(by),dy])+2]);

%定义各构件初始位置,定义线色、点型大小、擦除方式
l1=line([ax;bx(1)],[ay;by(1)],'color','b','linestyle','-','linewidth',2,...
    'erasemode','xor','parent',hh1);
l2=line([bx(1),cx(1)],[by(1),cy(1)],'color','b','linestyle','-',...
    'linewidth',2,'erasemode','xor','parent',hh1);
l3=line([ax,dx],[ay,dy(1)],'color','b','linestyle','-','linewidth',...
    2,'erasemode','xor','parent',hh1);
l4=line([cx(1),dx],[cy(1),dy],'color','b','linestyle','-','linewidth',...
    2,'erasemode','xor','parent',hh1);
%定义各铰链初始位置
h1=line(ax,ay,'Color',[1 0 0],'Marker','.','MarkerSize',20,...
    'EraseMode','xor','parent',hh1);
h2=line(bx(1),by(1),'Color',[1 0 0],'Marker','.','MarkerSize',...
    20,'EraseMode','xor','parent',hh1);
h3=line(cx(1),cy(1),'Color',[1 0 0],'Marker','.','MarkerSize',...
    20,'EraseMode','xor','parent',hh1);
h4=line(dx,dy,'Color',[1 0 0],'Marker','.','MarkerSize',20,...
'EraseMode','xor','parent',hh1);
theta1=theta1*180/pi;
if c==1
   xtick=0:30:360;
else
   xtick=-360:30:0;
end
hh2=handles.axes2;
plot(theta1,theta3*180/pi,'parent',hh2,'linewidth',2)
set(hh2,'XTick',xtick)
h5=line(theta1(1),theta3(1)*180/pi,'Color',[1 0 0],'Marker','.','MarkerSize',...
    20,'EraseMode','xor','parent',hh2);
set(get(hh2,'YLabel'),'String','摇杆角位移(rad)','Fontsize',10)
hh3=handles.axes3;
plot(theta1,omiga3,'parent',hh3,'linewidth',2)
set(hh3,'XTick',xtick)
set(get(hh3,'YLabel'),'String','摇杆角速度(rad/s)','Fontsize',10)
h6=line(theta1(1),omiga3(1),'Color',[1 0 0],'Marker','.','MarkerSize',...
    20,'EraseMode','xor','parent',hh3);
hh4=handles.axes4;
plot(theta1,alph3,'parent',hh4,'linewidth',2)
set(hh4,'XTick',xtick)
xlabel('曲柄转角(^o)','Fontsize',8);ylabel('摇杆角加速度(rad/s^2)','Fontsize',10);
h7=line(theta1(1),alph3(1),'Color',[1 0 0],'Marker','.','MarkerSize',...
    20,'EraseMode','xor','parent',hh4);
nn=str2double(get(handles.edit1,'String'));%仿真次数
mm=0;
while mm<nn
   for i=1;length(bx)
       set(h2,'xdata',bx(i),'ydata',by(i));
       set(h3,'xdata',cx(i),'ydata',cy(i));
       set(h5,'xdata',theta1(i),'ydata',theta3(i)*180/pi);
       set(h6,'xdata',theta1(i),'ydata',omiga3(i));
       set(h7,'xdata',theta1(i),'ydata',alph3(i));
       set(l1,'xdata',[ax;bx(i)],'ydata',[ay;by(i)]);
       set(l2,'xdata',[bx(i),cx(i)],'ydata',[by(i),cy(i)]);
       set(l4,'xdata',[cx(i),dx],'ydata',[cy(i),dy]);
pause(0.2)
drawnow
   end
   mm=mm+1;
end
cla(hh1)
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(~, ~, ~)
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
close(gcf)%关闭窗口,退出仿真


function edit1_Callback(~, ~, ~)
% hObject    handle to edit1 (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 edit1 as text
%        str2double(get(hObject,'String')) returns contents of edit1 as a double


% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, ~, ~)
% hObject    handle to edit1 (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
图片附件: 游客没有浏览图片的权限,请 登录注册
搜索更多相关主题的帖子: the line set base parent 
2018-06-18 00:26
快速回复:MATLAB中曲柄摇杆机构动画仿真分析,其中运行出现错误
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.027885 second(s), 12 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved