From: siew tee kong on
i have a GUI
In the GUI, there are 4 boxes.
The user keys in 3 values into the first 3 boxes and clicks GO.
Then the min will be displayed in the 4th box.

The tags for the boxes are UV_1, UV_2, UV_3, UV_4.

The following are my codes:
a = get(handles.UV_1,'String');
b = get(handles.UV_2,'String');
c = get(handles.UV_3,'String');

UV = [a b c];
min_UV = min(UV);

set(handles.UV_4, 'String', min_UV);
guidata(hObject, handles);

So if i key 2, 4, 6 in the forst 3 boxes, i shoudl get 2 as my min. However, i got 50 as my min.

What is wrong?
TQ
From: Walter Roberson on
siew tee kong wrote:

> The following are my codes:
> a = get(handles.UV_1,'String');
> b = get(handles.UV_2,'String');
> c = get(handles.UV_3,'String');

As the get() calls hint, "a" and "b" and "c" will all be strings.

> UV = [a b c];

[] in that form is the horizontal concatenation operator. The horizontal
concatenation of 3 strings is a single longer string such as '246'

> min_UV = min(UV);

Applying min() to a string returns the minimum UTF-16 character code
found in the string. In this case it would be the UTF-16 character code
for the character '2', which happens to be character code 50.

> set(handles.UV_4, 'String', min_UV);
> guidata(hObject, handles);
>
> So if i key 2, 4, 6 in the forst 3 boxes, i shoudl get 2 as my min.
> However, i got 50 as my min.
>
> What is wrong?

If you want to take the minimum of values that are represented as
strings, you have to somehow convert those strings into the values they
represent.
From: siew tee kong on
> If you want to take the minimum of values that are represented as
> strings, you have to somehow convert those strings into the values they
> represent.

How do i do this?

Doesnt set(handles.UV_4, 'String', min_UV); convert the string?

TQ
From: ImageAnalyst on
Use the str2double() function. Then you can take the min of your
strings/numbers.

a='123'
b='345'
dbl_a = str2double(a)
dbl_b = str2double(b)
min_ab = min([dbl_a, dbl_b])