Advertisement
NaroxEG

MatLab - Get Roots Btn

Dec 9th, 2024
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.48 KB | None | 0 0
  1. % --- Executes on button press in findRootsBtn.
  2. function findRootsBtn_Callback(hObject, eventdata, handles)
  3. rootsStr = get(handles.eqnInput, 'String');
  4. coeffsStr = strsplit(rootsStr, ' ');
  5. coeffs = str2double(coeffsStr);
  6.  
  7. if any(isnan(coeffs))
  8.     set(handles.text16, 'String', 'Error: Please enter valid numeric coefficients.');
  9.     return;
  10. end
  11.  
  12. rootsResult = roots(coeffs);
  13.  
  14. rootsFormatted = sprintf('%.4f\n', rootsResult);
  15.  
  16. set(handles.text16, 'String', rootsFormatted);
  17.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement