- output may change size: use empty numeric [].
- output must remain same size: use NaN.
Using App Designer, reading a numeric edit field and creating a double array from the inputs?
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have 3 NumericEditFields and I enter 5700 & 4750 in the first 2 (the 3rd can be blank and thus only have an array with only 2 elements). I then convert them from MegaHertz to Hertz by the following:
if isempty(app.NumericEditField_NotchCenterFreq1.Value) % check to see if the field is empty first, if so, assign an empty string
fc1 = {};
else
fc1 = app.NumericEditField_NotchCenterFreq1.Value;
fc1 = fc1 * 10e6; % Convert to Hertz
end
if isempty(app.NumericEditField_NotchCenterFreq2.Value)
fc2 = {};
else
fc2 = app.NumericEditField_NotchCenterFreq2.Value;
fc2 = fc2 * 10e6; % Convert to Hertz
end
if isempty(app.NumericEditField_NotchCenterFreq3.Value)
fc3 = {};
else
fc3 = app.NumericEditField_NotchCenterFreq3.Value;
fc3 = fc3 * 10e6; % Convert to Hertz
end
% Create an array from entered inputs
notch_fc=[fc1, fc2, fc3];
make_loadset(app, notch_fc);
The notch_fc array is
notch_fc: 1×2 cell array =
[1×4 double] [1×4 double]
But I want it to be a double array (values for example)
notch_fc: 1x2 double =
1.0e+09 *
5.7000 4.7500
How can I accomplish this? I have searched and searched and can not find the answer. Thanks in advance!
0 commentaires
Réponse acceptée
Stephen23
le 22 Avr 2023
Modifié(e) : Stephen23
le 22 Avr 2023
The reason why it is a cell array is because you told MATLAB to make a cell array. Basically you are doing this:
fc1 = 1;
fc2 = pi;
fc3 = {}; % if this is a cell array...
[fc1,fc2,fc3] % then so is this.
If any input to the concatenation operator is a cell array, then the output will be a cell array. This is explained here:
Ergo, if you do not want a cell array output, do not provide cell arrays as the inputs.
"How can I accomplish this? I have searched and searched and can not find the answer."
If you want a numeric vector output then you need to provide numeric inputs. Note that numeric arrays cannot have "holes" in them, i.e. every element must contain some value. Some solutions:
Lets try them both, right now:
fc3 = NaN; % numeric NaN
[fc1,fc2,fc3]
or
fc3 = []; % numeric empty
[fc1,fc2,fc3]
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!