How do i take complex number inputs in matlab appdesigner?

4 visualizaciones (últimos 30 días)
Samiul Hossain
Samiul Hossain el 12 de Feb. de 2022
Respondida: Voss el 12 de Feb. de 2022
I have to take both real and complex number inputs in appdesigner. I tried using Edit FIeld (Numeric) but it wont take complex inputs. Need something to take complex or real numbersas input

Respuestas (1)

Voss
Voss el 12 de Feb. de 2022
A NumericEditField cannot be used for complex numbers. From the documentation:
MATLAB rejects the value if:
  • It cannot convert the character vector to a scalar number.
  • The value is NaN, blank, or a complex number.
  • The value is a mathematical expression, such as 1 + 2.
  • The value is less than the Limits property lower limit or greater than the upper limit.
But you can use an EditField (not Numeric), in which case the Value will be a string or character vector, which you can convert to a number using str2double() (or str2num() if you need to allow non-scalars). For example:
str = app.my_edit_field.Value; % say str is '1+1i'
num = str2double(str); % then num is 1+1i

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by