MATLAB: Explain where I’ve gone wrong!

3dMATLABplottingpolygonshapes

To run this code you need to download the CSV file I have attached.
As you can see from my code, I have a 109×214 cell array which I reduce down and try to get some meaningful plots from. What I'm trying to do is plot a 3d polygon with all surfaces defined (i.e. lines connecting all points). I've managed to get the top and bottom of the shape, but can't work out why my code to draw the sides of the shape isn't working, i.e, this part
% Code for plotting sides of shape

for k = 1:sizelatlong(1,2)
plot3(long(1,k),lat(1,k),alt_data(1:2,k),'r*')
end
Can anyone help me out? Full code below.
clear all
close all
clc
[~, ~, aor] = xlsread('C:aor.csv','aor');
aor(cellfun(@(x) ~isempty(x) && isnumeric(x) && isnan(x),aor)) = {''};
sector = aor(:,2);
sector_req = 6;
%identify rows corresponding to required sector
rows = find(cell2mat(sector)==sector_req);
%reduce matrix
data_sector_all = aor(rows,:);
%check size
sizedsa = size(data_sector_all);
%convert relevant numbers
for y = 9:4:sizedsa(1,2)
for x = 1:sizedsa(1,1)
data_sector_all{x,y} = ((data_sector_all{x,y}/100)*59);
end
end
%calculate lat/long
for x = 1:sizedsa(1,1)
i = 1;
for y = 7:8:sizedsa(1,2)
%this line of code identifies whether the x,y position in
%data_sector_all is a number or []. If it's [], it doesn't do the
%for loop.
if ceil(data_sector_all{x,y}) == floor(data_sector_all{x,y})
lat(x,i) = data_sector_all{x,y} + (data_sector_all{x,(y+1)}/60) + (data_sector_all{x,(y+2)}/3600);
end
%check if point is south of equator
if data_sector_all{x,(y+3)} == 'S'
lat(x,i) = -lat(x,i);
end
i = i + 1;
end
end
for x = 1:sizedsa(1,1)
i = 1;
for y = 11:8:sizedsa(1,2)
if ceil(data_sector_all{x,y}) == floor(data_sector_all{x,y})
long(x,i) = data_sector_all{x,y} + (data_sector_all{x,(y+1)}/60) + (data_sector_all{x,(y+2)}/3600);
end
% check if point is east of London
if data_sector_all{x,(y+3)} == 'E'
long(x,i) = -long(x,i);
end
i = i + 1;
end
end
sizelatlong = size(lat);
%preallocate


lat(:,(sizelatlong(1,2)+1)) = 0;
% add an additonal value onto the end of the lat coordinate
for x = 1:sizelatlong(1,1)
lat(x,(sizelatlong(1,2)+1)) = lat(x,1);
end
%preallocate
long(:,(sizelatlong(1,2)+1)) = 0;
% add an additonal value onto the end of the long coordinate
for x = 1:sizelatlong(1,1)
long(x,(sizelatlong(1,2)+1)) = long(x,1);
end
%preallocate
alt_data = zeros(sizedsa(1,1)*2, sizelatlong(1,2)+1);
i = 1;
%define altitude data
for x = 1:sizedsa(1,1)
for y = 4:5
alt_data(i,:) = data_sector_all{x,y};
i = i + 1;
end
end
figure
hold on
%code for plotting top and bottom of shape
for x = 1:sizelatlong(1,1)
plot3(long(x,:),lat(x,:),alt_data(x,:))
plot3(long(x,:),lat(x,:),alt_data(x+1,:))
end
% Code for plotting sides of shape
for k = 1:sizelatlong(1,2)
plot3(long(1,k),lat(1,k),alt_data(1:2,k),'r*')
end
xlabel('Longitude (x) [degrees]')
ylabel('Latitude (y) [degrees]')
zlabel('Altitude (z) [feet]')

Best Answer

plot3(long(1,k),lat(1,k),alt_data(1:2,k),'r*-')
When you specify a marker, the line is turned off by default. If you want line and marker both then you need to include both codes.