Hello
at the moment I am working with a data structure, this structure is stored in appdata in a certain way.
in my mainGui I create a base cell array called plotTypeData, this is stored as
plotTypeData = cell(1,6);
setappdata(gcf, 'plotTypeData', plotTypeData);
setappdata(0, 'hMainGui', gcf);
in the mainGui openingfcn.
Now to why I need to check if the a structure exists: I have 6 other GUIs which are able to call the plotTypeData cell and alter it, when a secondary GUI have altered the contents of plotTypeData, it will store or update it as follows
setappdata(0, 'plotTypeData', plotTypeData);
The real problem occur, as one might have guessed, when a secondary GUI needs to get the data from plotTypeData. Because if a secondary GUI have not stored the plotTypeData in the root directory it is necessary to retrieve it from the mainGui handle, hMainGui. So what I am trying to figure out, is a way to check whether the plotTypeData struct exists in the root directory or not, and act accordingly. It needs to be mentioned that within plotTypeData cell are stored, making plotTypeData become a 1x1 struct.
in the root directory. This is done to ensure that plotTypeData is reachable by all GUIs.
any suggestions?
best regards
Steffan

 채택된 답변

Robert Cumming
Robert Cumming 2011년 5월 13일

1 개 추천

using
getappdata
without specifying the variable name will return a structure with all data as fields in it.

댓글 수: 5

Steffan
Steffan 2011년 5월 13일
thank very much for the quick respons, I will try this solution before I accept the answer :)
Steffan
Steffan 2011년 5월 13일
I still lack the opportnunity to check whether a certain struct/cell exists or not, within the code of course.
I am trying to act correct in the case that the plotTypeData does not exist in the root directory, and in the case that it does exist in the root directory.
Robert Cumming
Robert Cumming 2011년 5월 13일
getappdata ( 0 )
will get all data in a struct at the root.
Use:
isfield ( rootdata, 'plotTypeData')
to check if it exists.
Steffan
Steffan 2011년 5월 16일
works like a charm, thanks :)
sina kosari
sina kosari 2018년 1월 19일
편집: sina kosari 2018년 1월 19일
:) :) :) :) :) :) :) :) thanks :) :) :) :) :) :) :) :)

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

추가 답변 (1개)

Jan
Jan 2011년 5월 13일

4 개 추천

See the function: isappdata

댓글 수: 3

Steffan
Steffan 2011년 5월 16일
Too bad I can't accept two answers as isappdata also works perfectly :( but thanks
Arturo Moncada-Torres
Arturo Moncada-Torres 2011년 5월 16일
Give him a vote then ;) !
Steffan
Steffan 2011년 5월 16일
done ;)

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

카테고리

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

질문:

2011년 5월 13일

편집:

2018년 1월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by