필터 지우기
필터 지우기

GUIDE Handle not updating

조회 수: 1 (최근 30일)
Oliver Lestrange
Oliver Lestrange 2020년 8월 14일
편집: Bruno Luong 2020년 8월 14일
Hi,
I am using the following code.
function antennaId_Callback(hObject, eventdata, handles)
% hObject handle to antennaId (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns antennaId contents as cell array
% contents{get(hObject,'Value')} returns selected item from antennaId
contents = cellstr(get(hObject,'String')) % Options of popupmenu antennaId
selected = contents{get(hObject,'Value')} % Value selected by the user through popupmenu antennaId
currDir = strcat(pwd,'\')
handles.Antenna.Info = readAntenna(selected,currDir);
guidata(hObject, handles);
And then, when I call it here
function attenuationButton_Callback(hObject, eventdata, handles)
% hObject handle to attenuationButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%global ant; % Default Antenna
Aten=0;
handles = guidata(hObject)
handles.MS(1).x = 1:handles.map.xlength;
handles.MS(1).y = 1:handles.map.ylength;
handles.MS(1).height = 1.5; %m
handles.MS(1).gain = 2.4;
for i = 1:handles.nAntenna
Aten=Aten+1
handles.Antenna(i).Prx=attenuation( handles.map, handles.Antenna(i), handles.MS,...
handles.Antenna(i).Info);
end
Aten=1;
guidata(hObject, handles);
The variable handles.Antenna.Info exits, but in the loop it sends an empty array. At the first call has the handles.Antenna.Info, but the second time doesn't.
What I am doing wrong?
Thanks
  댓글 수: 4
Bruno Luong
Bruno Luong 2020년 8월 14일
편집: Bruno Luong 2020년 8월 14일
Who initializes handles.nAntenna ? Why antennaId_Callback initializes a single structure Antenna and attenuationButton_Callback use structure array (without MATLAB throwing an error)? What is "Aten", why it's not used anywhere?
It seems you still don't tell us the whole story.
Oliver Lestrange
Oliver Lestrange 2020년 8월 14일
The handles.nAntenna is initialized by the Opening Function.
antennaId_Callback initializes a single structure Antenna because I need that the user says "I want to use this antenna", and then, is going to select the positions where he wants the antenna (base station). Then, he can use the attenuationButton_Callback to see the number of antennas placed at the map, and the attenuation function will call some other functions that make the calculus to see in each position of the matrix(map) how attenuation the signal have.
Important notice that antennaId_Callback is a popupmenu.

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

채택된 답변

Walter Roberson
Walter Roberson 2020년 8월 14일
handles.Antena.Info = readAntenna(selected,currDir);
If handles.Antena is a scalar struct then that statement assigns to handles.Antena(1).Info but no other handes.Antena(i).info . If you later create more handles.Anten(i) entries and do not initialize the associated Info field, then the field would become empty.
If handles.Antena is a non-scalar structure, then handles.Antena.Info on the left would expand to multiple locations, and you would get an error message.
Because you did not get an error message at that point, we can deduce that at the point you assign to the Info field, either handles.Antena itself does not exist (in which case a scalar structure would be created) or else handles.Antena does exist as a scalar structure. If handles.Antena was a non-scalar structure then the assignment to Info would have failed.
for i = 1:handles.nAntenna
Aten=Aten+1
handles.Antenna(i).Prx=attenuation( handles.map, handles.Antenna(i), handles.MS,...
handles.Antenna(i).Info);
Somewhere in there, handles.Antenna got created as a non-scalar structure. But probably most of the Info fields are empty.
Notice that the first function initializes handles.Antena but in this second function you use handles.Antenna with two n's. Those are different variables.
  댓글 수: 7
Walter Roberson
Walter Roberson 2020년 8월 14일
After
handles.Antenna( handles.nAntenna ).height = handles.Antenna_height;
add
handles.Antenna( handles.nAntenna ).Info = handles.Antenna(1).Info;
Bruno Luong
Bruno Luong 2020년 8월 14일
See my answer bellow

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

추가 답변 (1개)

Bruno Luong
Bruno Luong 2020년 8월 14일
편집: Bruno Luong 2020년 8월 14일
Try to put this
[handles.Antenna(:).Info] = deal(readAntenna(selected,currDir));
in antennaId_Callback. (NOTE: You must call insertAntenna_Callback first).
  댓글 수: 2
Oliver Lestrange
Oliver Lestrange 2020년 8월 14일
Didn't work, but thanks a lot. Why did you suggest using deal function?
Bruno Luong
Bruno Luong 2020년 8월 14일
편집: Bruno Luong 2020년 8월 14일
DEAL will populate all the field Info of handles.Antenna structure array using a single output argument returned by readAntenna.
Now "Dind't work" alone doesn't allow me do make any useful comment/diagnostic. But I suspect is you call insertAntenna_Callback AFTER antennaId_Callback contraty to the instruction I gave. Since that will create a new structure at the end of the array and leaves Info field unpopulated, meaning having EMPTY as default value.
Anyway if you are happy with Walter's answer, then it's OK..

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

카테고리

Help CenterFile Exchange에서 MATLAB Mobile Fundamentals에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by