フィルターのクリア

How do I take complex number as an input and do operations on them in App Designer

3 ビュー (過去 30 日間)
youssef Mostafa
youssef Mostafa 2022 年 4 月 12 日
コメント済み: Chunru 2022 年 4 月 13 日
I want to take input from the user as a complex number and do simple operations on them.
  2 件のコメント
Rik
Rik 2022 年 4 月 12 日
What have you tried?
youssef Mostafa
youssef Mostafa 2022 年 4 月 12 日
Str2double but I couldn't get the output of the operation

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

回答 (1 件)

Chunru
Chunru 2022 年 4 月 12 日
編集済み: Chunru 2022 年 4 月 13 日
% Get s using input function
s = "2+3i";
x = str2double(s)
x = 2.0000 + 3.0000i
For GUI components:
% Assume that you have a uieditfield component in your GUI application
h = uieditfield('Posiion', [100, 175, 100, 25], 'Value', '3+2i');
% here h is the handle to the UI component
% In GUI design, you can set the callback function for "ValueChangedFcn"
% within the funtion, you can access the string
s = get(h, 'Value')
% Then convert to double
x = str2double(s)
% then perform any other operation on x
% Let the final result be y = f(x) as a complex number
% convert y to string
sout = num2str(y)
% Update the edit field (or something else)
set(h, 'Value', sout)
  8 件のコメント
Walter Roberson
Walter Roberson 2022 年 4 月 13 日
Unifortunately, uieditfield('numeric') does not handle complex numbers. You would need to use uieditfield() for a text field, and str2double()
Chunru
Chunru 2022 年 4 月 13 日
See the update for GUI component.

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

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by