Want to have an input in while loop

1 回表示 (過去 30 日間)
Abdulaziz Almuammar
Abdulaziz Almuammar 2017 年 6 月 12 日
回答済み: Rajanya 2024 年 11 月 18 日
I want to plot real time date using matlab. Those data I should be able to apply it manually
pressure = 0
x=0
while keep
x=[x,pressure];
plot(x);
grid
drawnow limitrate;
pause(1)
end
I want a way to to use input in side the while loop that will not stop the loop and when the user input a number that number will update the pressure.

回答 (1 件)

Rajanya
Rajanya 2024 年 11 月 18 日
You can use ‘inputdlg’ for this purpose to request input from the user.
The following line prompts the user to input appropriate ‘pressure’ value which is, by default, stored as an element of a cell array of character vector.
answer = inputdlg('Enter new pressure value:');
It is important to note here that this approach does not prevent the user from entering multiple or invalid inputs, so those checks need to be handled separately.
To convert ‘answer’ to a numeric array, ‘str2num’ can be used.
pressure = str2num(answer{1});
This ‘pressure’ value can then be used to plot the data accordingly.
For more details on ‘inputdlg’ and ‘str2num’, you can refer to their documentation pages by running the following commands in the MATLAB Command Window:
doc inputdlg
doc str2num
Hope this helps!

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by