Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solveEqnsBtn_Callback(hObject, eventdata, handles)
- % hObject handle to solveEqnsBtn (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- aVals = [];
- bVals = [];
- cVals = [];
- dVals = [];
- ConstVals = [];
- if get(handles.checkbox1, 'Value') == 1
- aVals = [aVals; str2double(get(handles.a1, 'String'))];
- ConstVals = [ConstVals; str2double(get(handles.Const1, 'String'))];
- end
- if get(handles.checkbox2, 'Value') == 1
- aVals = [aVals; str2double(get(handles.a2, 'String'))];
- bVals = [bVals; str2double(get(handles.b1, 'String'))];
- bVals = [bVals; str2double(get(handles.b2, 'String'))];
- ConstVals = [ConstVals; str2double(get(handles.Const2, 'String'))];
- end
- if get(handles.checkbox3, 'Value') == 1
- aVals = [aVals; str2double(get(handles.a3, 'String'))];
- bVals = [bVals; str2double(get(handles.b3, 'String'))];
- cVals = [cVals; str2double(get(handles.c1, 'String'))];
- cVals = [cVals; str2double(get(handles.c2, 'String'))];
- cVals = [cVals; str2double(get(handles.c3, 'String'))];
- ConstVals = [ConstVals; str2double(get(handles.Const3, 'String'))];
- end
- if get(handles.checkbox4, 'Value') == 1
- aVals = [aVals; str2double(get(handles.a4, 'String'))];
- bVals = [bVals; str2double(get(handles.b4, 'String'))];
- cVals = [cVals; str2double(get(handles.c4, 'String'))];
- dVals = [dVals; str2double(get(handles.d1, 'String'))];
- dVals = [dVals; str2double(get(handles.d2, 'String'))];
- dVals = [dVals; str2double(get(handles.d3, 'String'))];
- dVals = [dVals; str2double(get(handles.d4, 'String'))];
- ConstVals = [ConstVals; str2double(get(handles.Const4, 'String'))];
- end
- A = [aVals bVals cVals dVals];
- sol = A\ConstVals;
- solStr = arrayfun(@(x) sprintf('%.2f', x), sol, 'UniformOutput', false);
- while numel(solStr) < 4
- solStr{end+1} = 'N/A'; % Append 'N/A' for missing values
- end
- % Create the result string dynamically
- resultTxt = sprintf('X1 = %s\nX2 = %s\nX3 = %s\nX4 = %s\n', solStr{:});
- set(handles.text18, 'String', resultTxt)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement