assign cell arrays in an array

2 visualizaciones (últimos 30 días)
Evangelos Xenos
Evangelos Xenos el 18 de Nov. de 2022
Respondida: Bala Tripura Bodapati el 21 de Nov. de 2022
Hello everyone,
I have this script of code, part of a bigger program, and I need to save the jammer and eavs position values [#, #, #] in a list/array every time my NCS_r is greater than the assigned threshold. How do I input these values into an array? I have tried amending them in ALL_jammer_pos[] and ALL_eavs_pos, but didn't work (it's in comments the relevant lines of code).
here is the code:
Rt= ##;
ALL_jammer_pos= [];
ALL_eavs_pos= [];
for ii=1:1:10000
...
for iii=1:1:1000
jammer_posx = randi([-500 500],1,1);
%fprintf('%d', jammer_posx);
jammer_posy = randi([-500 500],1,1);
eavs_posx = randi([-500 500],1,1);
eavs_posy = randi([-500 500],1,1);
jammer= [jammer_posx jammer_posy H];
eavs= [eavs_posx eavs_posy H];
...
NCS_r= ###;
% if NCS_r >= Rt
% ALL_jammer_pos= [ALL_jammer_pos jammer];
% ALL_eavs_pos= [ALL_eavs_pos eavs];
% end
end
The jammer and eavs positions come in the format of a 1x3 double, where 1st value is the X-axis value, 2nd the Y-axis value and 3rd the Z-axis value. Z-axis value is fixed as the Height operating in, which is not crucial to be kept necessarily.
Do you have any ideas how I can put all the jammer and eavs position values in relative arrays/lists to keep record of the positions used?

Respuestas (1)

Bala Tripura Bodapati
Bala Tripura Bodapati el 21 de Nov. de 2022
Hi Evangelos
It is my understanding that you would like to iteratively append the 'jammer' and 'evas' positions to an array when a specified condition is satisfied.
As the dimension of the variables 'jammer' and 'evas' is [1x3], a possible workaround is to use 'cell arrays' to store the value of the variables in every iteration whenever the specified condition is satisfied.
The following code illustrates the use of cell arrays as mentioned above:
Rt= 30;
ALL_jammer_pos= {};
ALL_eavs_pos= {};
for ii=1:1:10000
for iii=1:1:1000
jammer_posx = randi([-500 500],1,1);
%fprintf('%d', jammer_posx);
jammer_posy = randi([-500 500],1,1);
eavs_posx = randi([-500 500],1,1);
eavs_posy = randi([-500 500],1,1);
H=30;
jammer= [jammer_posx jammer_posy H];
eavs= [eavs_posx eavs_posy H];
NCS_r= 40;
if NCS_r >= Rt
ALL_jammer_pos{end+1}= jammer;
ALL_eavs_pos{end+1}= eavs;
end
end
end
Refer the cell array documentation for information on using cell arrays.

Categorías

Más información sobre Structures en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by