⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 s_parmosm2.m

📁 带电粒子在电磁场中运动轨迹模拟程序
💻 M
📖 第 1 页 / 共 3 页
字号:
    factor_velocity = 10^value;
end

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

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end
    global_variables;
    value = 5.0;
    set(hObject,'Value', value);
    factor_velocity = 10^value;
end

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

% Hint: get(hObject,'Value') returns toggle state of rbuttGuideCenter
    global_variables;
    guide_set = get( hObject, 'Value' );
end

% --- Executes on selection change in popElecField.
function popElecField_Callback(hObject, eventdata, handles)
% hObject    handle to popElecField (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns popElecField contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popElecField

    global_variables;
    
    switch get(handles.popElecField, 'Value')
        case EFIELD_NONE                                % no electric field is selected
            set(handles.stextElecField, 'Visible', 'Off');
            set(handles.edtElecField, 'Visible', 'Off');
            
        case EFIELD_CONSTANT                            % constant electric field in x direction
            set(handles.stextElecField, 'Visible', 'On');
            set(handles.stextElecField, 'String', 'Define electric field strength [V/m]');
            set(handles.edtElecField, 'Visible', 'On');
            set(handles.edtElecField, 'String', '100.0');
            
        case EFIELD_CUSTOM                              % custom electric field
            set(handles.stextElecField, 'String', 'Define electric field [Ex, Ey, Ez]. Instead of the coordinates xyz use R(1)R(2)R(3). Example: [ 0, (R(1)+R(2))/Sqrt(R(1)^2+R(2)^2+R(3)^2), R(3)/Sqrt(R(1)^2+R(2)^2+R(3)^2) ]');
            set(handles.stextElecField, 'Visible', 'On');
            set(handles.edtElecField, 'Visible', 'On');
            set(handles.edtElecField, 'String', '[ 0, 0, 0 ]');                           
    end

end

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

% Hint: popupmenu 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
end


function edtElecField_Callback(hObject, eventdata, handles)
% hObject    handle to edtElecField (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 edtElecField as text
%        str2double(get(hObject,'String')) returns contents of edtElecField as a double
end

% --- Executes during object creation, after setting all properties.
function edtElecField_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edtElecField (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
end


function edtInitPos_Callback(hObject, eventdata, handles)
% hObject    handle to edtInitPos (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 edtInitPos as text
%        str2double(get(hObject,'String')) returns contents of edtInitPos as a double
end

% --- Executes during object creation, after setting all properties.
function edtInitPos_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edtInitPos (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
end


function edtInitVel_Callback(hObject, eventdata, handles)
% hObject    handle to edtInitVel (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 edtInitVel as text
%        str2double(get(hObject,'String')) returns contents of edtInitVel as a double
end

% --- Executes during object creation, after setting all properties.
function edtInitVel_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edtInitVel (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
end


function edtMass_Callback(hObject, eventdata, handles)
% hObject    handle to edtMass (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 edtMass as text
%        str2double(get(hObject,'String')) returns contents of edtMass as a double
end

% --- Executes during object creation, after setting all properties.
function edtMass_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edtMass (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
end


function edtCharge_Callback(hObject, eventdata, handles)
% hObject    handle to edtCharge (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 edtCharge as text
%        str2double(get(hObject,'String')) returns contents of edtCharge as a double
end

% --- Executes during object creation, after setting all properties.
function edtCharge_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edtCharge (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
end

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

    global_variables;
    
    switch status
        case STATUS_STOP
            % start the simulation
            % simulation is stopped and it has to be initialized and
            % restarted
            
            % prepare all simulation information
            prepare_information( handles );
            
            if field_BfunctionOK == 1 & field_EfunctionOK == 1
                % start initialization
                initialization( handles );

                % change the text on button to "Pause Simulation"
                set(handles.pbuttGoSimulate, 'String', 'Pause simulation' );
                pause(0.1);
                % change status to STATUS_RUNNING
                status = STATUS_RUNNING;

                % start simulation
                simulation_run( particle_initVel, particle_initPos, handles );
            end;
            
        case STATUS_RUNNING
            % pause simulation
            % it pause or stop with the status change
            
            % change the text on button to "Restart Simulation"
            set(handles.pbuttGoSimulate, 'String', 'Restart simulation' );
            pause(0.1);
            % change status to STATUS_PAUSED
            status = STATUS_PAUSED;
            
            % save the world for further applications
            vrdrawnow;
            save(w, get(w, 'FileName'));            
            
        case STATUS_PAUSED
            % change the text on button to "Pause Simulation"            
            set(handles.pbuttGoSimulate, 'String', 'Pause simulation' );
            pause(0.1);
            % change status to STATUS_RUNNING
            status = STATUS_RUNNING;
            
            % unpause simulation         
            simulation_run( particle_vel, particle_pos, handles );  
            
        case STATUS_FIELDS_SET
            % change the text on button to "Pause Simulation"
            set(handles.pbuttGoSimulate, 'String', 'Pause simulation' );
            pause(0.1);
            % change status to STATUS_RUNNING
            status = STATUS_RUNNING;
            
            % start simulation
            simulation_run( particle_initVel, particle_initPos, handles );
    end
end

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

    switch status
        case STATUS_STOP
            % don't change anything
            
        case STATUS_RUNNING
            %offer saving simulation
            
            % change the text on start button "Start Simulation"            
            set(handles.pbuttGoSimulate, 'String', 'Start simulation' );            
            
            % change status to STATUS_STOP
            status = STATUS_STOP;
            
        case STATUS_PAUSED
            % stop simulation
            
            %offer saving simulation
            
            % change the text on start button "Start Simulation"            
            set(handles.pbuttGoSimulate, 'String', 'Start simulation' );
            
            % change status to STATUS_STOP
            status = STATUS_STOP;
    end
    % save the vr world for further applications
    vrdrawnow;
    save(w, get(w, 'FileName'));
end



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

% Hint: get(hObject,'Value') returns toggle state of rbuttonVectorForce
    global_variables;
    vectorForce_set = get( hObject, 'Value' );
end

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

% Hint: get(hObject,'Value') returns toggle state of rbuttonVectorVelocity
    global_variables;
    vectorVel_set = get( hObject, 'Value' );
end

% --- Executes on button press in pbuttShowFields.
function pbuttShowFields_Callback(hObject, eventdata, handles)
% hObject    handle to pbuttShowFields (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
    
    global_variables;
    
    
    % prepare all simulation information
    prepare_information( handles );

    % start initialization
    initialization( handles );
    
    status = STATUS_FIELDS_SET;
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -