Get user input on string, ideally using uicontrol?

6 ビュー (過去 30 日間)
Hugh
Hugh 2023 年 4 月 1 日
コメント済み: Hugh 2023 年 4 月 5 日
So, I've been asked to make a script that determines an ID from the filename of an imported file. For instance, something like RN101_HF_523HFC.xls might lead to an ID of RN101_HF, and I just want to make something like a popup window that asks the user if the string 'RN101_HF' is correct, and allow them to edit it however they'd like. The ideal solution for me would be something like a popup window that has a prompt asking them to confirm the ID, with an editable text field that is already filled in with the ID generated by the code, and a confirmation button.
I have literally no idea how to do this in matlab, but I've seen that uicontrol might be able to do something like this? I can't seem to find any helpful guides on using uicontrol though from what I've seen.

採用された回答

Walter Roberson
Walter Roberson 2023 年 4 月 1 日
See https://www.mathworks.com/help/matlab/ref/inputdlg.html and in particular the default input option.
[filename, pathname] = uigetfile('*.xls', 'Choose file');
if ~ischar(filename); return; end %user cancel
ID = regexp(filename, '^[^_]+_[^_.]+', 'match');
if isempty(ID); [~, ID, ~] = fileparts(filename); end %case in which the ID is wrong form to guess
Now call inputdlg using ID as the default input.
  1 件のコメント
Hugh
Hugh 2023 年 4 月 5 日
Thanks man. I haven't looked closely at your code, as I'd already set that part up (I was just trying to do the dialog box part). The inputdlg function was exactly what I was looking for though! Pretty much exactly the default code did exactly what I wanted it to.
Btw, I've now got another question regarding the easiest way to setup a checkbox dialog box? Pretty much, I want exactly what inputdlg does, but with checkboxes instead of edit text fields. I'm about to post another question for this purpose.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by