I want to store the values in a new 2d array, values are already stored in "distance_nod.inrange" array, how it is possible?

1 view (last 30 days)
% plot the targets
clear ; clc; close all;
targets = 5;
X_position = [45 55 45 37 38 ];
Y_position = [65 63 72 58 60];
figure; clf ;hold on; t=0;s=0; xlabel('X-axis '); ylabel('Y-axis ');
hold on
for i = 1:targets
t=t+1;
T(t, :) = [X_position(i) Y_position(i)]; %assign targets coordinate value into array tar....
plot(X_position(i), Y_position(i),'*','Color','r');
axis([1,100,1,100]); % draw the nodes inside the figure
axis equal
end
%----------------------------------------------------------------
sensor = 4;
X_position_sensor = [51 48 65 35 ];
Y_position_sensor = [74 55 67 65 ];
hold on
b=0;
for ii = 1:sensor
s=s+1;
b=b+1;
S(s, :) = [X_position_sensor(ii) Y_position_sensor(ii)]; %assign sensor coordinate value into array sens....
battery(b,:)=1; %assign battery to sensor that is 1 unit
plot(X_position_sensor(ii),Y_position_sensor(ii),'.','color','b');
axis([1,100,1,100]); % draw the nodes inside the figure
axis equal
end
%----------------------------------------------------------------
Trange=15;
targets = 5;
X_position = [45 55 45 37 38 ];
Y_position = [65 63 72 58 60];
sensor = 4;
X_position_sensor = [51 48 65 35 ];
Y_position_sensor = [74 55 67 65 ];
hold on
for ii=1: sensor
for i=1:targets % plot the circular transmission range that are in range
distance_nod.node = sqrt((X_position(i)-X_position_sensor(ii))^2 + (Y_position(i) - Y_position_sensor(ii))^2);
if distance_nod.node <= Trange
distance_nod.inrange(ii,i)=1;
disp(circle(X_position_sensor(ii),Y_position_sensor(ii),Trange));
hold on
else
distance_nod.inrange(ii,i)=0;
end
end
display(distance_nod.inrange) % <------on that point ,next i want to store values in 2d array
function [xunit,yunit] = circle(x,y,r)
hold on
th = 0:pi/50:2*pi;
xunit = r * cos(th) + x;
yunit = r * sin(th) + y;
h = plot(xunit, yunit);
hold off
end

Accepted Answer

Iñigo Escanciano
Iñigo Escanciano on 24 Jun 2021
First, I guess your last for statement is missing an end after the following code line:
display(distance_nod.inrange) % <------on that point ,next i want to store values in 2d array
I assume it is a typo copying the code, if not it would not work.
Then, you can just instead of displaying the variable, save it by typing:
new2darray = distance_nod.inrange
I suggest doing it after the missing end

More Answers (0)

Categories

Find more on Graphics Object Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!