add values to my matrix each time i click on the button gui

조회 수: 3 (최근 30일)
omar Benamiar Messari
omar Benamiar Messari 2018년 7월 16일
댓글: omar Benamiar Messari 2018년 7월 16일
Hello, i need to know how can we add values to our matrix each time i click on a button, i declared a global variable matrix, but each time i have the same values, i used this method in the button_callback
A = [1 2 3;
4 5 6]
newrow = [x y z]; % value to add
%add a row to existing matrix:
A = [A; newrow]
my problem is that i always have 3*3 matrix even if i'm pushing the button several time so, if you have any idea please help.
thanks and sorry for my bad english
  댓글 수: 1
omar Benamiar Messari
omar Benamiar Messari 2018년 7월 16일
a also did this but have the same problem.
function gui1_OpeningFcn(hObject, eventdata, handles, varargin)
handles.matrix=[];
function start_Callback(hObject, eventdata, handles)
newrow=[8,8,8,8];
handles.matrix=[handles.matrix;newrow];
guidata(hObject, handles);

댓글을 달려면 로그인하십시오.

답변 (1개)

Andy
Andy 2018년 7월 16일
Each time the code runs you are setting the matrix A to its start value, a 2 x 3 matrix, then adding row three. The answer will always be a 3 x 3 matrix. You need to store the current value of the matrix globally then just add the new row.
  댓글 수: 1
omar Benamiar Messari
omar Benamiar Messari 2018년 7월 16일
i already did that but it's not working,
function varargout = gui1(varargin) global matrix; matrix=[];
this button to add values to my matrice
function start_Callback(hObject, eventdata, handles) global matrix; newrow=[15,0,0,0]; matrix=[matrix;newrow];
did i did something wrong ?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Function Creation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by