Adding and saving a structure array in GUI

Hi!
I'm developing a GUI where the user can introduce mechanical properties of two diferente materials and obtain the mechanical properties of a single material that is the result of the both previous ones.
In this GUI the user gives a name to the "final" material and can save it's mechanical properties. These values are saved in a structure array called Ply_prop."material name"!
My problem is that if I save a 1st material, for example called "aaa", and when I run the GUI again, and I want to add and save a new material, for example called "bbb", to the structure array Ply_prop, my code don't save Ply_prop.aaa and Ply_prop.bbb!!! The code just overwrite the structure array Ply_prop, deleting aaa and just saving bbb!
Here is my code:
function Save_btn_Callback(hObject, eventdata, handles)
% hObject handle to Save_btn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
guidata(hObject, handles)
name = num2str(get(handles.ply_name_in,'String'))
if (get(handles.C_VF_btn,'Value')==1)
VF = str2num(get(handles.C_in,'String'))
FM = str2num(get(handles.C_out,'String'))
else
FM = str2num(get(handles.C_in,'String'))
VF = str2num(get(handles.C_out,'String'))
end
E1 = str2num(get(handles.C_E1_out,'String'))
E2 = str2num(get(handles.C_E2_out,'String'))
Poisson = str2num(get(handles.C_poisson_out,'String'))
Shear = str2num(get(handles.C_shear_out,'String'))
X = str2num(get(handles.C_X_out,'String'))
Y = str2num(get(handles.C_Y_out,'String'))
ShearS = str2num(get(handles.C_shearS_out,'String'))
load counter.mat
if counter==1
counter=counter+1;
Ply_prop.(name)(1,1)=FM
Ply_prop.(name)(2,1)=VF
Ply_prop.(name)(3,1)=E1
Ply_prop.(name)(4,1)=E2
Ply_prop.(name)(5,1)=Poisson
Ply_prop.(name)(6,1)=Shear
Ply_prop.(name)(7,1)=X
Ply_prop.(name)(8,1)=Y
Ply_prop.(name)(9,1)=ShearS
save ('Ply_prop.mat','-struct','Ply_prop')
end
if counter>1
load Ply_prop.mat
Ply_prop.(name)(1,1)=FM
Ply_prop.(name)(2,1)=VF
Ply_prop.(name)(3,1)=E1
Ply_prop.(name)(4,1)=E2
Ply_prop.(name)(5,1)=Poisson
Ply_prop.(name)(6,1)=Shear
Ply_prop.(name)(7,1)=X
Ply_prop.(name)(8,1)=Y
Ply_prop.(name)(9,1)=ShearS
save ('Ply_prop.mat','-struct','Ply_prop')
end
save ('counter.mat','counter')
%counter is just a variable used to verify if the material that is being saved is the first one in the struture array Ply_prop!!
Thanks in advance!
Best regards,
Frederico Ferreira

 Réponse acceptée

Geoff
Geoff le 19 Mar 2012
You need to call:
Ply_prop = load('Ply_prop.mat');
Otherwise all the fields from your struct will be loaded in as variables.

1 commentaire

Frederico
Frederico le 19 Mar 2012
Thank you very much for your answer!! I was convinced that this problem wasn't a big one, however it was turning into a big problem to solve for me!!
Thanks again!
Best regards!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Programming dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by