Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

variable changes when reading it from user gui

1 visualizzazione (ultimi 30 giorni)
Mustafa Al-Nasser
Mustafa Al-Nasser il 25 Ago 2020
Chiuso: MATLAB Answer Bot il 20 Ago 2021
Hello,
I'm writing a software that needs to read some data from a code file, pass it to a user window where the user can change them, then read them back and do some calculations to present an output.
My process goes as follows:
However, the output is not what was expected based on the inputs, so i changed my code so that code file B pass the varables diretly to the function without going through the user window, so it is something like this:
output B was the correct output (i.e. the expected one based on the variables), so when i ran the first program i enter the same variables that was based on the second one, logically speaking, the output of both programs should be the same, they both have the same inputs and same functions, however output A does not equal to output B.
I tried to compare the variables when reading them directly from the previous file and when reading them after going through the gui, when i print them i can see they are the same, but when i use a function like isequal or directly using == the output is 0 (it says they are different), i also compared the size and the type of variables and it is all the same (Visually) but passing them to isequal function says they are differnt.
i concluded that there is some change made when i read them from the user gui, but this change is invisible to me, so what would be the solution to such problem?
Thank you all

Risposte (1)

Image Analyst
Image Analyst il 25 Ago 2020
Try using ismembertol() instead of isequal or ==.
Are you getting the variables directly, or pulling them from a static text label or edit text box? If you go through a text control on the GUI, then make sure you're using num2str() or sprintf(), and str2double() because the contents of text controls are strings, not numbers.
  2 Commenti
Mustafa Al-Nasser
Mustafa Al-Nasser il 25 Ago 2020
I used ismembertol and same output when using isequal (when comparing with the text input it says 0)
and yes, i'm reading the data from an edit text box and i used both str2num and str2double to convrt them but same issue
Image Analyst
Image Analyst il 25 Ago 2020
Can't really do much without the code. So I'd just suggest normal debugging:

Community Treasure Hunt

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

Start Hunting!

Translated by