continious Zero Matrix filling

I have a GUI in which ill enter values and save those variables in one Matrix. So every time i enter variables and push the button i want the matrix to get populated continiously.
Here is my work so far:
sc = [d, l, hs1, hs2, bs1, bs2, phi1, phi2]; % vecotr in which the variables are written in
mat=zeros(100,8); % Zero Matrix with 8 columns for the 8 variables and 100 rows max.
mat(1,1:length(sc))=sc % here i want to write the vektor into the zero matrix
% save in variable setappdata(0,'sc',sc)
i dont know how i can write the code for adding the variables into the zero matrix without erasing the last ones. so every time i push the button in the gui i want the vector sc to be saved in the zero matrix .
thanks

 채택된 답변

Nirmal
Nirmal 2012년 6월 6일

0 개 추천

In that case you need to setup a counter lets say cnt
cnt=0%initialization at the very beginning
Now you need to use the counter as the index. Where you want to use a loop or not is totally upto you and the application you are building.
sc = [d, l, hs1, hs2, bs1, bs2, phi1, phi2]; % vecotr in which the variables are written in
mat(cnt,1:length(sc))=sc % here i want to write the vektor into the zero matrix
cnt=cnt+1;%increment the counter

댓글 수: 8

Smiljan
Smiljan 2012년 6월 6일
thanks for the help. i am still having problems.
when i write cnt=0 there is an error in matlab because it says indices must be real positive.
here is my code :
cnt=1;
sc = [d, l, hs1, hs2, bs1, bs2, phi1, phi2];
mat=zeros(10,8);
mat(cnt,1:length(sc))=sc % here i want to write the vektor into the zero matrix
cnt=cnt+1;%increment the counter
every time i push the button it only writes down the vektor in the first row and overwrites its when pushing again with new numbers
Smiljan
Smiljan 2012년 6월 6일
sorry this is my for loop :
sc = [d, l, hs1, hs2, bs1, bs2, phi1, phi2];
mat=zeros(10,8);
for cnt=1;
mat(cnt,1:length(sc))=sc % here i want to write the vektor into the zero matrix
cnt=cnt+1;%increment the counter
end
Nirmal
Nirmal 2012년 6월 6일
your initialization of the counter shouldnot be done inside the event handler for the push button, it should be initialized else where(probably at the time when your GUI loads), then every time the button is pushed you save the vector into the matrix and increment the counter and save it again. You might want to save it into handles. like
%initialization
handles.cnt=1;
guidata(hObject,handles);
-----------------------------------
%inside the button event handler.
cnt=handles.cnt;
%now you can use the counter as the index. You need to increment and save it again into the handle.
Smiljan
Smiljan 2012년 6월 6일
thanks again for the help. i would never thought of initializing at the opening function instead of the push button function.
do i need a loop for that or is it possible without?
Nirmal
Nirmal 2012년 6월 6일
no you dont need anyloop.
Smiljan
Smiljan 2012년 6월 6일
so without any loop and can also write it like this?:
% in the push button function:
cnt=handles.cnt;
sc = [d, l, hs1, hs2, bs1, bs2, phi1, phi2];
mat=zeros(10,8);
mat(cnt,1:length(sc))=sc % here i want to write the vektor into the zero matrix
cnt=cnt+1;%increment the counter
Smiljan
Smiljan 2012년 6월 7일
Sorry for bothering again. I still have problems with this.
Here is what i wrote in the opening GUI function:
handles.cnt=1; %start the counter
handles.mat=zeros(10,8);% zero matrix
guidata(hObject,handles);
Here the push button function:
sc = [d, l, hs1, hs2, bs1, bs2, phi1, phi2];
mat=handles.mat;
cnt=handles.cnt;
mat(cnt,1:8)=sc; % here i want to write the vektor into the zero matrix
cnt=cnt+1;
handles.cnt=cnt ; %increment the counter
handles.mat=mat;
guidata(hObject,handles);
what could be the problem?
Smiljan
Smiljan 2012년 6월 7일
now it works :)

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Exponents and Logarithms에 대해 자세히 알아보기

질문:

2012년 6월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by