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 commentaires

Rik
Rik le 14 Août 2020
Did you make sure antennaId_Callback runs before attenuationButton_Callback? And did you check the output of readAntenna?
Oliver Lestrange
Oliver Lestrange le 14 Août 2020
Modifié(e) : Oliver Lestrange le 14 Août 2020
Yes Rik.
But a weird thing is happening and I don't know why. In the loop, the first call has the handles.Antenna.Info, but the second time don't.
Sorry I forgot to mencioned this important thing before.
Bruno Luong
Bruno Luong le 14 Août 2020
Modifié(e) : Bruno Luong le 14 Août 2020
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 le 14 Août 2020
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.

Connectez-vous pour commenter.

 Réponse acceptée

Walter Roberson
Walter Roberson le 14 Août 2020

0 votes

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 commentaires

Oliver Lestrange
Oliver Lestrange le 14 Août 2020
"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." - That was a translation problem. I switched to English for you understand better the code.
I think you are completely right. But how can I do it? How can I put the info returned by readAntenna in all positions of the loop? Because if I use handles.Antenna.Info in the loop, instead fo handles.Antenna(i).Info I have the same problem, at the first time I have the structure an at the second is an empty one.
Walter Roberson
Walter Roberson le 14 Août 2020
Since it will be the same for all entries (if I understand you correctly) then pass handles.Antenna(1).Info
Oliver Lestrange
Oliver Lestrange le 14 Août 2020
I changed it to handles.Antenna(1).Info in the loop and it still not working. I've try put handles.Antenna(1).Info in the return of readAntenna to, and same thing...just the first position has the structure.
:(
Bruno Luong
Bruno Luong le 14 Août 2020
I repeat "It seems you still don't tell us the whole story."
Somewhere else the Antenna structure array is initialized and it's not in the two functions you have posted.
No one can help if you hide the details.
function insertAntenna_Callback(hObject, eventdata, handles)
% hObject handle to insertAntenna (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%[x_gNB, y_gNB] = ginput(1);
[pos, ~] = axisInput(handles.mapPlace);
x_gNB = pos(1,1);
y_gNB = pos(1,2);
handles.nAntenna = handles.nAntenna + 1
Antenna_x = x_gNB;
Antenna_y = y_gNB;
rectangle('Position', [(Antenna_x - handles.Rwidth/2) (Antenna_y - handles.Rheight/2)...
handles.Rwidth handles.Rheight], 'FaceColor', 'r','LineStyle', 'none');
handles.Antenna( handles.nAntenna ).Antenna_x = Antenna_x;
handles.Antenna( handles.nAntenna ).Antenna_y = Antenna_y;
handles.Antenna( handles.nAntenna ).height = handles.Antenna_height;
guidata(hObject, handles)
The axisInput is like a ginput.
handles.Antenna_height is initialized in the opening function like the handles.nAntenna.
The rest of the functions and callbacks use handles.Antenna after.
After
handles.Antenna( handles.nAntenna ).height = handles.Antenna_height;
add
handles.Antenna( handles.nAntenna ).Info = handles.Antenna(1).Info;
Bruno Luong
Bruno Luong le 14 Août 2020
See my answer bellow

Connectez-vous pour commenter.

Plus de réponses (1)

Bruno Luong
Bruno Luong le 14 Août 2020
Modifié(e) : Bruno Luong le 14 Août 2020

0 votes

Try to put this
[handles.Antenna(:).Info] = deal(readAntenna(selected,currDir));
in antennaId_Callback. (NOTE: You must call insertAntenna_Callback first).

2 commentaires

Oliver Lestrange
Oliver Lestrange le 14 Août 2020
Didn't work, but thanks a lot. Why did you suggest using deal function?
Bruno Luong
Bruno Luong le 14 Août 2020
Modifié(e) : Bruno Luong le 14 Août 2020
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..

Connectez-vous pour commenter.

Catégories

En savoir plus sur MATLAB 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