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 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Image Analyst
il 3 Mag 2022
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?
Risposte (1)
vidyesh
il 18 Ott 2023
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.
0 Commenti
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!