Creating structure array and store it in mat file!

hello!
I am working in signature recognition system my final project, I have many variable and I want to store it in structure array then I save the structure array in a mat file. but there is a problem, when I store data in the 1st index then 2nd then third... so on when I want to access the data from the 1st index it give me an empty variable. my data is (image,name of person, lastname, ID, complex number,double number) and I get all these data from interface. I have put the below code in push button_callback:
name=get(handles.edit2, 'string');
lastname= get(handles.edit3, 'string');
id= get(handles.edit4, 'string');
A = handles.amplitud;
Phi = handles.phi;
array(1).name = name;
array(1).lastname = lastname;
array(1).amplitud = A;
array(1).phi = Phi;
array(1).ID = id;
save('Database.mat','array');
when I want to get the 1st index data I write like this:
array(1).name
but I get something like this:
ans =
[]
I can just access the last index data.
it is very difficult problem for me. if some one know answer me.
thanks

Answers (1)

Perhaps you define the structure incorrect,

5 Comments

thanks sir!
I saw your link, but I think my code is correct. there is another problem.
answer me please.
thanks!
You have defined correctly. i just tested your code, and it works OK for me. Perhaps the problem lies in other part of the code (that you didn't post)?
name='name';
lastname='lastname';
id= '007';
A = 500;
Phi = 3.14;
array(1).name = name;
array(1).lastname = lastname;
array(1).amplitud = A;
array(1).phi = Phi;
array(1).ID = id;
>> save('Database.mat','array');
>> load('Database.mat', 'array')
>> array(1).name
ans =
name
thanks again! sir it works in command window good, but it dose not work in my interface I enter the value of variables(name, lastname, ID,A,Phi) by interface then by pressing the button it is stored in matfile.
I don't know what is the problem!
help me please!
sorry for my bad English!
thanks
From your code, i can guess that it is actually part of a GUI script. What do you call by interface is actually what i (we) call GUI (Graphical User Interface).
The problem you've mentioned its still rather sketchy. Can you confirm several things beforehand?
  1. Does your GUI code have something like this (in line 21)? %See also: GUIDE, GUIDATA, GUIHANDLES
  2. Can you confirm that Database.mat is saved?
  3. Did you call array(1).name inside GUI? or do you call it in command windows?
1. Yes.
2. No.
3. Yes I call array(1).name inside GUI.
I think you found its problem sir!
thank you for your response!

Sign in to comment.

Tags

No tags entered yet.

Asked:

on 20 Jan 2015

Edited:

on 25 Jan 2015

Community Treasure Hunt

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

Start Hunting!