inputdlg Window Not Showing

6 ビュー (過去 30 日間)
Jaiden
Jaiden 2024 年 5 月 31 日
編集済み: Manikanta Aditya 2024 年 5 月 31 日
So I was creating an even or odd checker using inputdlg. However, when I ran it, the inputdlg window actually does not show up. Here is the code/proof that I used so far.
prompt={"Enter a 1 x 1 integer value:"}
dlgtitle="Even or odd test"
tmp=inputdlg(prompt,dlgtitle)
user_number=round(str2double(tmp))
if not(isnan(user_number))
fprintf("Number is valid.\n")
if rem(user_number,2)==0
fprintf("Your number is even.\n")
else
fprintf("Your number is odd.\n")
end
else
fprintf("Number is not valid.\n")
end
There aren't any errors or warnings shown on there. Can someone tell me if there is a way to get the inputdlg window to show (if it has something to do with the code)?

採用された回答

Manikanta Aditya
Manikanta Aditya 2024 年 5 月 31 日
編集済み: Manikanta Aditya 2024 年 5 月 31 日
Your code for checking even or odd numbers using 'inputdlg' looks mostly correct, but if the 'inputdlg' window isn't showing up, it might be due to a few reasons, such as issues with MATLAB's graphical interface or script execution.
  1. Ensure that MATLAB’s graphical user interface components are not disabled or malfunctioning,
  2. Add semicolons to the script.
  3. And check tf the script if its calling the inputdlg.m
Try this, I checked in my MATLAB R2024a, and it works:
prompt = {"Enter a 1 x 1 integer value:"};
dlgtitle = "Even or odd test";
tmp = inputdlg(prompt, dlgtitle);
if ~isempty(tmp) % Check if inputdlg returned a value
user_number = round(str2double(tmp{1}));
if ~isnan(user_number)
fprintf("Number is valid.\n");
if rem(user_number, 2) == 0
fprintf("Your number is even.\n");
else
fprintf("Your number is odd.\n");
end
else
fprintf("Number is not valid.\n");
end
else
fprintf("No input provided.\n");
end
Hope this helps.

その他の回答 (1 件)

Image Analyst
Image Analyst 2024 年 5 月 31 日
I ran it and it works fine for me. The input window popped up.
Your script in not called inputdlg.m is it? Because that would be a problem.
  1 件のコメント
Manikanta Aditya
Manikanta Aditya 2024 年 5 月 31 日
+1

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

カテゴリ

Help Center および File ExchangeImage Data Workflows についてさらに検索

タグ

製品


リリース

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by