How to better utilize 'input'?

조회 수: 3 (최근 30일)
Chad Pilbeam
Chad Pilbeam 2018년 3월 25일
답변: Walter Roberson 2018년 3월 25일
I am trying to create a program that will take user inputs for different force vectors and weights and the like. I want to make the code give an error message, and re-prompt the user to input an integer if the user inputs a character instead, without the program crashing and MatLab errors being displayed. Any help on how to do this?

채택된 답변

Star Strider
Star Strider 2018년 3월 25일
I prefer the inputdlg (link) function. It saves the input values to a cell array, so you can then convert and check them yourself before looping back if a returned value is not what you want. If you are requesting multiple inputs, you can even save the correct inputs as the default values so the user doesn’t have to re-enter them.
  댓글 수: 2
Chad Pilbeam
Chad Pilbeam 2018년 3월 25일
Thanks!
Star Strider
Star Strider 2018년 3월 25일
My pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2018년 3월 25일

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by