Error using bin2dec (in App Designer)
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello, I have to do a program to convert decimal to binary, octal and hexamdecimal and vice versa, when I did the decimal to binary conversion everything went well, but when I convert from decimal to binary I have problems.
Every time I enter a decimal number in the EditField, it throws me this message: "Input argument must be a character vector, string, or cell array of character vectors."
I have understood that in the EditField I have to convert the values that I enter into a vector (so to speak)
So as I do when I enter binary numbers in the EditField it returns me the result in decimal.
function ConvertirButtonPushed(app, event)
% De Decimal a los otros
if(app.DecimalButton.Value)
% Example - Decimal to Binary
result_2 = dec2bin(app.IngreseunnumeroEditField.Value);
app.BinarioTextArea.Value = num2str(result_2);
end
% Error - Binary to Decimal
if(app.BinarioButton.Value)
result_1 = bin2dec(app.IngreseunnumeroEditField.Value);
app.DecimalTextArea.Value = num2str(result_1);
end
end
0 comentarios
Respuestas (1)
Walter Roberson
el 28 de Mzo. de 2021
result_2 = dec2bin(app.IngreseunnumeroEditField.Value);
You say that works, but for that to work, IngreseunnumeroEditField must be returning a numeric value not text
result_1 = bin2dec(app.IngreseunnumeroEditField.Value);
The exact same field is being used, but for bin2dec to function it must be passed a character vector, but we established above it is numeric instead.
You need to make the edit field text instead of numeric, and for the dec2bin case, str2double the text before passing it in.
Do not take the route of instead converting the numeric value to text to pass into bin2dec: if you do that then you will fail if the user enters more than 16 bits.
0 comentarios
Ver también
Categorías
Más información sobre Data Type Conversion en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!