Senyokbalgul
Senyokbalgul

Reputation: 1102

How to allow a vector input in Matlab GUI `edit text`

The code below will work if the numerical input is a single scalar, but won't work if it is a vector. I would like the user to input the vector in the format of [5 5 5].

handles.brightness = str2double(get(hObject,'String'));

I would like to store the vector values in an empty array zeros(1,3). Then I could do something like handles.brightness(1) or handles.brightness(2) to use the vector elements.

Upvotes: 0

Views: 927

Answers (1)

mhopeng
mhopeng

Reputation: 1081

You can use str2num instead of str2double:

a = str2num('[5 5 5]')

a =

     5     5     5

>> a(2)

ans =

     5

b = str2double('[5 5 5]')

b =

   NaN

str2num is more flexible than str2double but there is a cost in security and performance. See the docs for details.

Upvotes: 2

Related Questions