📄 gui_grid1.m
字号:
% 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 planes as text% str2double(get(hObject,'String')) returns contents of planes as a double% --- Executes during object creation, after setting all properties.function planes_CreateFcn(hObject, eventdata, handles)% hObject handle to planes (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');endfunction cubes_Callback(hObject, eventdata, handles)% hObject handle to cubes (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 cubes as text% str2double(get(hObject,'String')) returns contents of cubes as a double% --- Executes during object creation, after setting all properties.function cubes_CreateFcn(hObject, eventdata, handles)% hObject handle to cubes (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');endfunction dot_s_num_Callback(hObject, eventdata, handles)% hObject handle to dot_s_num (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 dot_s_num as text% str2double(get(hObject,'String')) returns contents of dot_s_num as a double% --- Executes during object creation, after setting all properties.function dot_s_num_CreateFcn(hObject, eventdata, handles)% hObject handle to dot_s_num (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');endfunction cube_s_num_Callback(hObject, eventdata, handles)% hObject handle to cube_s_num (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 cube_s_num as text% str2double(get(hObject,'String')) returns contents of cube_s_num as a double% --- Executes during object creation, after setting all properties.function cube_s_num_CreateFcn(hObject, eventdata, handles)% hObject handle to cube_s_num (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');endfunction dotss_Callback(hObject, eventdata, handles)% hObject handle to dotss (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 dotss as text% str2double(get(hObject,'String')) returns contents of dotss as a double% --- Executes during object creation, after setting all properties.function dotss_CreateFcn(hObject, eventdata, handles)% hObject handle to dotss (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');endfunction cubess_Callback(hObject, eventdata, handles)% hObject handle to cubess (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 cubess as text% str2double(get(hObject,'String')) returns contents of cubess as a double% --- Executes during object creation, after setting all properties.function cubess_CreateFcn(hObject, eventdata, handles)% hObject handle to cubess (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 cube_s_num_dots.function cube_planes_Callback(hObject, eventdata, handles)% hObject handle to cube_s_num_dots (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)%读取uicontrol中x,y,z,a,b,c的值并计算各坐标轴单位长度的个数x=str2num(get(handles.x_edit,'String'));y=str2num(get(handles.y_edit,'String'));z=str2num(get(handles.z_edit,'String'));a=str2num(get(handles.a_edit,'String'));b=str2num(get(handles.b_edit,'String'));c=str2num(get(handles.c_edit,'String'));m=x/a;n=y/b;p=z/c;%调用画图函数重新做图以消除可能存在的以前的操作结果draw(m,n,p);%读取uicontrol中cube_s_num的值cube_s_num=str2num(get(handles.cube_s_num,'String'));%判断cube_s_num是否符合实际if cube_s_num>m*n*p set(handles.planess,'String',strcat('',num2str('error')));elseif cube_s_num<=0 set(handles.planess,'String',strcat('',num2str('error')));else cube_s_num<=m*n*p %计算cube_s_num的块坐标zz = fix((cube_s_num-1)/(m*n));yy = fix((cube_s_num-1-zz*m*n)/m);xx = fix(cube_s_num-1 - zz*m*n - yy*m);%定义并初始化cube点的坐标矩阵cube_s_dot = zeros(8,3);%定义并初始化cube点的编号矩阵cube_s_dot_num = zeros(8,1);cube_s_dot(1,:) = [xx,yy,zz]';cube_s_dot(2,:) = [xx+1,yy,zz]';cube_s_dot(3,:) = [xx,yy+1,zz]';cube_s_dot(4,:) = [xx+1,yy+1,zz]';cube_s_dot(5,:) = [xx,yy,zz+1]';cube_s_dot(6,:) = [xx+1,yy,zz+1]';cube_s_dot(7,:) = [xx,yy+1,zz+1]';cube_s_dot(8,:) = [xx+1,yy+1,zz+1]';%计算cube点的编号for dot_cnt = 1:1:8 cube_s_dot_num(dot_cnt) = cube_s_dot(dot_cnt,1) + cube_s_dot(dot_cnt,2)*(m+1) + cube_s_dot(dot_cnt,3)*(m+1)*(n+1)+1;end%定义cube面编号矩阵计算cube各面的编号cube_s_plan_num = zeros(6,1);temp_num = cube_s_dot_num(1);temp_x = cube_s_dot(1,1);temp_y = cube_s_dot(1,2);temp_z = cube_s_dot(1,3);cube_s_plan_num(1) = temp_num - temp_z*(m+n+1)-temp_y;temp_num = cube_s_dot_num(5);temp_x = cube_s_dot(5,1);temp_y = cube_s_dot(5,2);temp_z = cube_s_dot(5,3);cube_s_plan_num(2) = temp_num - temp_z*(m+n+1)-temp_y; temp_num = cube_s_dot_num(1);temp_x = cube_s_dot(1,1);temp_y = cube_s_dot(1,2);temp_z = cube_s_dot(1,3);cube_s_plan_num(3) = m*n*(p+1) + temp_num - temp_z*(m+1);temp_num = cube_s_dot_num(2);temp_x = cube_s_dot(2,1);temp_y = cube_s_dot(2,2);temp_z = cube_s_dot(2,3);cube_s_plan_num(4) = m*n*(p+1)+ temp_num - temp_z*(m+1); temp_num = cube_s_dot_num(1);temp_x = cube_s_dot(1,1);temp_y = cube_s_dot(1,2);temp_z = cube_s_dot(1,3);cube_s_plan_num(5) = m*n*(p+1) + n*p*(m+2) + temp_num - (temp_y+temp_z*(n+1));temp_num = cube_s_dot_num(3);temp_x = cube_s_dot(3,1);temp_y = cube_s_dot(3,2);temp_z = cube_s_dot(3,3);cube_s_plan_num(6) = m*n*(p+1) + n*p*(m+2) + temp_num - (temp_y+temp_z*(n+1));%在uicontrol中输出各面的编号set(handles.planess,'String',strcat('',num2str(cube_s_plan_num')));%将组成cube各面的线段用蓝色点作出for z=zz:(zz+1) for y=yy:(yy+1) for k=xx:xx x=k:0.025:k+1; plot3(x,y,z,'b'); hold on; end endendfor z=zz:(zz+1) for x=xx:(xx+1) for e=yy:yy y=e:0.025:e+1; plot3(x,y,z,'b'); hold on; end endendfor x=xx:(xx+1) for y=yy:(yy+1) for f=zz:zz z=f:0.025:f+1; plot3(x,y,z,'b'); hold on; end endend end% --------------------------------------------------------------------function Close_Callback(hObject, eventdata, handles)% hObject handle to Close (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)close% --------------------------------------------------------------------function Play_Callback(hObject, eventdata, handles)% hObject handle to Play (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)play_Callback(hObject, eventdata, handles)% --------------------------------------------------------------------function Cubes_Callback(hObject, eventdata, handles)% hObject handle to Cubes (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)dot_cubes_Callback(hObject, eventdata, handles)% --------------------------------------------------------------------function Dots_Callback(hObject, eventdata, handles)% hObject handle to Dots (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)cube_dots_Callback(hObject, eventdata, handles)function plane_s_num_Callback(hObject, eventdata, handles)% hObject handle to plane_s_num (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 plane_s_num as text% str2double(get(hObject,'String')) returns contents of plane_s_num as a double% --- Executes during object creation, after setting all properties.function plane_s_num_CreateFcn(hObject, eventdata, handles)% hObject handle to plane_s_num (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');endfunction liness_Callback(hObject, eventdata, handles)% hObject handle to liness (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 liness as text% str2double(get(hObject,'String')) returns contents of liness as a double% --- Executes during object creation, after setting all properties.function liness_CreateFcn(hObject, eventdata, handles)% hObject handle to liness (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 plane_lines.function plane_lines_Callback(hObject, eventdata, handles)% hObject handle to plane_lines (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)%读取uicontrol中x,y,z,a,b,c的值并计算各坐标轴单位长度的个数x=str2num(get(handles.x_edit,'String'));y=str2num(get(handles.y_edit,'String'));z=str2num(get(handles.z_edit,'String'));a=str2num(get(handles.a_edit,'String'));b=str2num(get(handles.b_edit,'String'));c=str2num(get(handles.c_edit,'String'));m=x/a;n=y/b;p=z/c;%调用画图函数重新做图以消除可能存在的以前的操作结果draw(m,n,p);%读取uicontrol中plane_s_num的编号plane_s_num=str2num(get(handles.plane_s_num,'String'));%判断plane_s_num是否符合实际if plane_s_num>m*p*(n+1)+n*p*(m+1)+m*(p+1)*n set(handles.liness,'String',strcat('',num2str('error')));elseif plane_s_num<=0 set(handles.liness,'String',strcat('',num2str('error'))); %平行于XOY面的平面elseif plane_s_num<=m*(p+1)*n %计算plane_s_num的块坐标zz = fix((plane_s_num-1)/(m*n));yy = fix((plane_s_num-1-zz*m*n)/m);xx = fix(plane_s_num-1 - zz*m*n - yy*m);%定义点的坐标矩阵plane_s_dot = zeros(4,3);plane_s_dot(1,:) = [xx,yy,zz]';plane_s_dot(2,:) = [xx+1,yy,zz]';plane_s_dot(3,:) = [xx,yy+1,zz]';plane_s_dot(4,:) = [xx+1,yy+1,zz]';%定义线的编号矩阵plane_s_line_num = zeros(4,1);%计算线的编号temp_x =plane_s_dot(1,1) ;temp_y =plane_s_dot(1,2) ;temp_z =plane_s_dot(1,3);plane_s_line_num(1) = temp_x+1+temp_z*m*(n+1)+temp_y*m;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -