that code does not work well and every time give the same number 5 times every time and not indexd to be used in an another place thank you

1 回表示 (過去 30 日間)
no=5;
x=zeros(no,1);
for i=1:no
waitfor(app.refindexEditField,'value');
x(i)=app.refindexEditField.Value;
end
app.refindexEditField.Value=inf;
fprintf(' %.1f \n ',x)
plot(app.UIAxes,(1:no)',x(1:i),'-r')
  2 件のコメント
Walter Roberson
Walter Roberson 2025 年 1 月 10 日
You have a different problem: your code does not permit entering the same value twice in a row. The value property is not considered to have changed if it is set to the same thing as at was before. You would need something like
app.refindexEditField.Value=inf;
before the waitfor()

サインインしてコメントする。

採用された回答

Umar
Umar 2025 年 1 月 10 日

Hi @m.montaser sabry,

The problem arises from the way the code is structured, particularly with the waitfor function. This function halts execution until the specified condition is met, which may lead to repeated values if the input field is not updated correctly. To resolve this, consider using a callback function that triggers when the value in app.refindexEditField changes. Here’s a revised approach:

no = 5;
x = zeros(no, 1);
for i = 1:no
  % Wait for user input
  app.refindexEditField.Value = input('Enter a value: '); % Prompt for input
  x(i) = app.refindexEditField.Value; % Store the input value
end
app.refindexEditField.Value = inf; % Reset the input field
fprintf(' %.1f \n ', x);
plot(app.UIAxes, (1:no)', x, '-r');

In this version, the user is prompted to enter a value directly in the command window, ensuring that each input is unique. This method allows for better control over the input process and prevents the same value from being recorded multiple times.

  6 件のコメント
m.montaser sabry
m.montaser sabry 2025 年 1 月 12 日

Dear Umar many many thanks for you ,you put me on the right track and with some modifications it gives nice results. First I deleted str2doble it is good without it. Second I transfer plot to runbuttonpushed function do well what I want. Thanks a lot again, Could you send me your email to get some of your talent.

m.montaser sabry
m.montaser sabry 2025 年 1 月 12 日

And also change app.refindexEditField.Value = inf Instead of ‘’ Thank you

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by