How do I run a loop where at each step, it will ask the user if the position index is valid and allow the user to manually adjust the value if it is not?

조회 수: 1 (최근 30일)
Hello, this is my first time asking a question so pardon me. I am currently working on trying to find a vortex center using the region with max vertical vorticity. I have the code and data to generate an imagesc of the vertical vorticity and the location where MATLAB thinks is the highest vertical vorticity. Unfortunately, sometimes MATLAB will identify another area where the vorticity is higher but I know the vortex center is not (we can see the vortex move in space). I was wondering if in a for loop is there a way to run through the entire code up to displaying the vorticity field and location of vorticity max (again which I have already done) then at the end, ask if the postion of the vorticity max is valid. If it is, the loop wil save the value and continue. If the user finds the postion invalid, the code will allow the user to adjust the postion of the vorticity max based on the graphic of the vorticity field.
  댓글 수: 2
Image Analyst
Image Analyst 2022년 5월 3일
I don't know why MATLAB would give you the location of the highest vorticity that is not correct. How did you ask MATLAB to identify that location? Can you attach your data, the code where you asked MATLAB for the location of vorticity max, and the location where you think the max actually, truly is?
Marco Paredes
Marco Paredes 2022년 5월 3일
Well it is not fair to say MATLAB is incorect. However, once a vortex forms, single pixels of high vorticity throw off the center. I cannot attach data becasue the file is just too big. The attached image shows what is going on. The image on the left is centered correctly. However, on the next time step we see the center starting to move off the vortex entering the feeder band. I want it to stay on the center

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

답변 (1개)

vidyesh
vidyesh 2023년 10월 18일
Hi Marco,
I understand that you are seeking to verify the validity of a vorticity maximum position that has been calculated and assigned at the end of a loop. If the position is found to be invalid, you would like to adjust it using user input.
To achieve this, you can utilize the input function. This function allows you to display text to the user and wait for their input. By incorporating an if condition based on the user's input value, you can execute a block of code that enables the user to input the correct value.
Below is a simple example of how this can be implemented. Please note that you can also use strings such as 'Yes' or 'No' for user input and modify the condition within the if block accordingly.
A = zeros(2,2);
for i = 1:2
for j = 1:2
A(i,j) = i*j; %Relevant value is calculated.
disp(sprintf("Value is %d\n",A(i,j) )); %Value is displayed to user.
dec = input('Is the value correct?\n'); % Prompt is displayed and user can input a value.
if dec == 0 %Loop is entered only if user inputs 0
temp = input('Enter the correct value\n'); %User enters the correct/desired value.
A(i,j) = double(temp); %The relevant value is updated.
end
end
end
Refer the following documentation for more information on ‘input’ function.
Hope this answer helps.

카테고리

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