How to change only one input if needed?
조회 수: 1 (최근 30일)
이전 댓글 표시
clc
close all;
n= input ('enter number of degree of freedoms')
m= input ('enter the values in mass(kg) matrix row wise -')
k= input ('enter the values in stiffness(N/m) matrix row wise-')
c= input ('enter the values in damping matrix -')
f= input ('enter the number of force vectors-')
x0 = input('enter the displacement(m) column matrix row wise-')
x0_dot = input('enter the velocity(m/s) column matrix row wise-')
THESE are my inputs for user if they entered any of value wrong for a variable then i need to restart everything. Please help me how to solve this.Thanks
댓글 수: 0
답변 (2개)
KSSV
2020년 10월 22일
prompt = "Enter number greater than 5 " ;
m = input(prompt) ;
while m > 5
m = input(prompt) ;
end
댓글 수: 0
Andy
2020년 10월 22일
I do not know how complex you have to get with the answer but, rather than using input(....) a better way would be to use app designer to create a gui with 7 inputs and a button to start the processing. You can run error checking on the inputs as they are completed ensuring the inputs are the same size and the values will still be in the gui if there is an error you haven't detected.
댓글 수: 2
Andy
2020년 10월 22일
Jus tthought that a simpler way than a gui is to use inputdlg but if you have to use input you could try something like this for each data entry
Datacheck = 0;
while Datacheck == 0
n = input ('Enter number of degree of freedom - ');
getreply = input('Are you happy with the data? 1 for Yes, 0 for No');
if getreply == 1
Datacheck = 1;
end
end
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!