Updating Matrix in GUI program

Hi,
I'm working on a GUI project, which I have to update a matrix in separate steps and at the final step calculate the values. In the other word, if I want to explain more, I have a 10*10 matrix that each line have to update in each button press and then move to the next line.
I used asignin() which just update one line and change the previous values or lines to zero.
Now, my question is how can I save my matrix with avoiding to miss the previous values?
Thanks for your time

 Respuesta aceptada

Jan
Jan el 28 de Feb. de 2013

0 votos

Instead of ASSIGNIN which is prone to errors, store the matrix using GUIDATA in the figure.
You can set the 'Enable' property of all buttons to 'off', except for the next allowed one. Then the callback of a button disable its own button and enables the following one.

7 comentarios

Ali
Ali el 28 de Feb. de 2013
Editada: Ali el 28 de Feb. de 2013
Hi Jan, Thanks for your answer. But the point is I have to have my values in work space as well, maybe this question is very basic, but I'm quite new with GUI, is GUIDATA send the data to the workspace? below is my code
A=zeros(10);
i = str2double(get(handles.node_number,'string'));
x = str2double(get(handles.x_value,'string'));
y = str2double(get(handles.y_value,'string'));
j=1;
le_value=sqrt(x^2+y^2);
set(handles.le_value,'string',le_value);
A(i,j)=i;
A(i,2)=x;
A(i,3)=y;
A(i,5)=le_value;
A
assignin('base', 'A',A);
set(handles.node_number,'string',i+1);
set(handles.x_value,'string',0);
set(handles.y_value,'string',0);
set(handles.le_value,'string',0);
I wrote this code in my next button how can I use GUIDATA instead of assignin? Thanks again
Jan
Jan el 28 de Feb. de 2013
Replace "assignin('base', 'A',A);" by:
handles = guidata(hObject); % If not done already
handles.A = A;
guidata(hObject, handles);
See help guidata and doc guidata - Matlab's documentation is very good and I can recommend to read it frequently. Searching for "guidata" in this forum will find many corresponding discussions.
Ali
Ali el 28 de Feb. de 2013
Editada: Ali el 28 de Feb. de 2013
Thanks, but I still lose the previous data
A =
1.0000 10.0000 10.0000 0 14.1421
A =
0 0 0 0 0
2.0000 5.0000 5.0000 0 7.0711
you can see in second matrix I do not have the first row any more
Jan
Jan el 28 de Feb. de 2013
Please post the relevant part of your code. It seems like you forgot to obtain the old A before appending the new data.
Ali
Ali el 28 de Feb. de 2013
here is my next button code
function next_Callback(hObject, eventdata, handles)
i = str2double(get(handles.node_number,'string'));
x = str2double(get(handles.x_value,'string'));
y = str2double(get(handles.y_value,'string'));
j=1;
le_value=sqrt(x^2+y^2);
set(handles.le_value,'string',le_value);
A(i,j)=i;
A(i,2)=x;
A(i,3)=y;
A(i,5)=le_value;
A
handles = guidata(hObject);
handles.A = A;
guidata(hObject, handles);
set(handles.node_number,'string',i+1);
set(handles.x_value,'string',0);
set(handles.y_value,'string',0);
set(handles.le_value,'string',0);
user has to push the button in order to go to the next node. And after the push, some of text boxes has to reset and the rest will be calculated for the next node, but now, as I said earlier I have to fix this problem then can add other things.
Thanks for help, I really appreciate that.
Ali
Ali el 6 de Mzo. de 2013
Hi Jan,
Can you please take a look at my code to see what is wrong with that? really need to solve this problem!
Jan
Jan el 6 de Mzo. de 2013
What is the problem exactly? I still do not get this.
The 'string' property of the UICONTROLs must be set to a string. Therefore this should be improved:
set(handles.le_value,'string',le_value)
set(handles.x_value,'string',0);
To:
set(handles.le_value,'string', sprintf('%g', le_value))
set(handles.x_value,'string', '0');

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Etiquetas

Preguntada:

Ali
el 28 de Feb. de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by