I'm trying to write a GUI for several purposes, that looks like this,
one of them is create a matrix based on user input via a uitable, so in the untitled_OpeningFcn
it was predefined the size and enabled the cell edition
set(handles.uitable1,'Data',cell(2,3));
set(handles.uitable1,'ColumnEditable',true(1,3))
inside the pushbutton2_Callback
, I try to read the data written in the table, store it and display in a static text field:
value=get(handles.uitable1,'Data');
value=str2double(value);
set(handles.text2,'String',num2str(value));
But when it is running the text field says "NaN"
, so the data is not being saved.
What else it is needed?
UPDATE
Thanks by the aswer it does not give the expected results
When using the original code it gives the next output
and when using the suggeste mat2str I got this
I believe the reason for your problem is that the line
value = get(handles.uitable1,'Data');
doesn't result in anything that is convertible to a number. Consider the following example:
hF = uifigure(); % works the same way with `figure()`.
hT = uitable(hF,'Data',[1 2 3; 4 5 6]);
Then, consider the following:
>> hT.Data
ans =
1 2 3
4 5 6
>> class(hT.Data)
ans =
'double'
>> str2double(hT.Data)
ans =
NaN
>> mat2str(hT.Data)
ans =
'[1 2 3;4 5 6]'
In conclusion - what you need is likely mat2str
.