How to change only one input if needed?

조회 수: 1 (최근 30일)
Venkata Rama Krishna Gona
Venkata Rama Krishna Gona 2020년 10월 22일
댓글: Andy 2020년 10월 22일
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

답변 (2개)

KSSV
KSSV 2020년 10월 22일
prompt = "Enter number greater than 5 " ;
m = input(prompt) ;
while m > 5
m = input(prompt) ;
end

Andy
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
Venkata Rama Krishna Gona
Venkata Rama Krishna Gona 2020년 10월 22일
My apologies sir, I havnt got your answer since i dont have much knowledge in the MATLAB. my question was the user will serially enters his values in the above mentioned way. if suppose he entered a values for 'm,k,c,f..' and then for 'k' he entered a wrong value now i need a way to correct only 'k' keeping all the other values intact. please help me i really appreaciate it.thanks
Andy
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

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

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by