Info

此问题已关闭。 请重新打开它进行编辑或回答。

variable changes when reading it from user gui

2 次查看(过去 30 天)
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

回答(1 个)

Image Analyst
Image Analyst 2020-8-25
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 个评论
Mustafa Al-Nasser
Mustafa Al-Nasser 2020-8-25
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

此问题已关闭。

Community Treasure Hunt

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

Start Hunting!

Translated by