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

I want to take input from the user as a complex number and do simple operations on them.

Answers (1)

% 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 Comments

I have already done this; how can I make operations on them and take the output on what kind of edit box
What do you mean? You can use that x in any operation that supports complex inputs.
Also, have you read the documentation for the input function?
No, I have not read the documentation. and also why would I need input function? The user puts the input in the editField. Also if the operation is done on the complex number, How can I display it? (numeric or text)
Where does the input number come from? Is it a user input from command line or an edit box from GUI?
Where does the output should go? Is it command window or GUI?
If it is a GUI, you need the handle to the GUI component. Post your code if possible.
What do you mean by handle to the GUI component?
I haven't written the code yet, but basically the user enters some values some are complex and some are real through GUI components. I want toake some mathematical operations on them and get the output on the edit field (which I don't know it's type yet numeric or text)
Unifortunately, uieditfield('numeric') does not handle complex numbers. You would need to use uieditfield() for a text field, and str2double()

Sign in to comment.

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Products

Asked:

on 12 Apr 2022

Commented:

on 13 Apr 2022

Community Treasure Hunt

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

Start Hunting!