error Structure assignment to non-structure object

Dear,
I am a beginner in programming matlab. In looking around, I have come across a function which looks like:
for j=1: FUE_Num_eachFemto
for i=1:HeNB_Num/4 %Generates Femtocell 1 to 4
x=rand(1)*10; %Generates random variables
y=rand(1)*10; %Generates random variables
FAP(i).location_x=x; %Femtocell Access Point location
end
end
i have problem "FAP(i).location_x=x;" error Structure assignment to non-structure object
thanks!

2 件のコメント

Geoff Hayes
Geoff Hayes 2016 年 10 月 19 日
Marwen - you may need to show more of your code. Even with dummy values for FUE_Num_eachFemto and HeNB_Num, I don't observe any problem with the above code.
Marwen Tarhouni
Marwen Tarhouni 2016 年 10 月 19 日
Dear, this is my code with values for FUE_Num and HeNB_Num
clc;
clear ;
HeNB_Num=16;
FUE_Num_eachFemto=1; %Number of UE in each unit
Throughput5_total1=1;
Throughput3_total1=1;
for HeNB_Num=4:4:16
%Throughput_total=zeros(4);
clear FAP;
FAP = zeros(1,HeNB_Num/4);
tic;
for j=1: FUE_Num_eachFemto
for i=1:HeNB_Num/4 %Generates Femtocell 1 to 4
x=rand(1)*10; %Generates random variables
y=rand(1)*10; %Generates random variables
FAP(i).location_x=x; %Femtocell Access Point location
FAP(i).location_y=y+(i-1)*10;
thanks!

サインインしてコメントする。

回答 (1 件)

KSSV
KSSV 2016 年 10 月 19 日

0 投票

Error comes in here. FAP(i).location_x=x; FAP is not a structure. It is a non structure and it is already initialized. Check what is FAP. Or try to put different name for instead of FAP. See the below error:
K =rand(10) ;
K(1).location = 10 ;
Structure assignment to non-structure object.
Error in impulse (line 4)
K(1).location = 10 ;
K is a matrix, I tried to associate a filed to it. As K is not a structure, error popped out.

4 件のコメント

KSSV
KSSV 2016 年 10 月 19 日
You have initialized FAP as a matrix.
FAP = zeros(1,HeNB_Num/4);
And making it a structure. Instead of zeros make it a structure.
FAP = struct;
Marwen Tarhouni
Marwen Tarhouni 2016 年 10 月 19 日
Dear, When i remove FAP
FAP = zeros(1,HeNB_Num/4);
other problem for syntaxe
FAP(i).location_x=x; %Femtocell Access Point location
FAP(i).location_y=y+(i-1)*10;
error ///// the variable 'FAP' appears to change size on every loop iteration (within a script).Consider preallocating for speed
Consider preallocating a variable or array before
entering the loop by using zeros, ones, cell, or a
similar function. Preallocating avoids the need for
MATLAB to copy the data from one array to another
inside the loop. For examples of code that do and do *
not preallocate an array, see “Preallocating Arrays”
how to solve this problem
thanks!!
KSSV
KSSV 2016 年 10 月 20 日
It is not throwing any error in my pc. What version you are using?
Marwen Tarhouni
Marwen Tarhouni 2016 年 10 月 20 日
matlab R2015a

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

2016 年 10 月 18 日

コメント済み:

2016 年 10 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by