Index exceeds matrix dimensions ( Error in intersection Points)

2 visualizaciones (últimos 30 días)
Akhil Narayanan
Akhil Narayanan el 2 de Jun. de 2021
Comentada: Akhil Narayanan el 2 de Jun. de 2021
Hi,
I am trying to plot shorelines by plotting intersection of a line and curve with which the output being generated should be a csv file with intersection points and a figure with plotted points. But there seems to be an error in the program as the figure is generated but the csv file is not getting generated. Attaching the code file (.m file) with input files. (line file and point curve file)
The error is,
Index exceeds matrix dimensions.
Error in Intersection_points (line 85)
plot(x0n(1),y0n(1),'bd');
The code I have written is,
%% clear all the background works
clc; clear all;
%% Select transects files
[fileName, pathName] = uigetfile('*.csv'); % Transects=csvread('DUMA_StartEnd_of_shoreline_transects.csv');
Transects = xlsread(fullfile(pathName,fileName)) ;
%% select shorelines file
[fileName, pathName] = uigetfile('*.csv'); %Shorelines=csvread('dubaim.20171119.gmt1319.autocad.csv');
Shorelines = xlsread(fullfile(pathName,fileName)) ;
%% Making transects
dc=3 % amount decimals precision
L={}
transectslength = length(Transects);
for n=1:1:transectslength
xn=[Transects(n,1) Transects(n,3)];
yn=[Transects(n,2) Transects(n,4)];
plot(xn,yn,'*')
hold on
hl=plot(xn,yn,'b-')
% Capturing segment points needed to get to intersections
kx=10^-dc*(linspace(10^dc*xn(1,1),...
10^dc*xn(1,2),...
max(abs(10^dc*xn(1,1)-10^dc*xn(1,2)),abs(10^dc*yn(1,1)-10^dc*yn(1,2)))));
ky=10^-dc*(linspace(10^dc*yn(1,1),...
10^dc*yn(1,2),...
max(abs(10^dc*xn(1,1)-10^dc*xn(1,2)),abs(10^dc*yn(1,1)-10^dc*yn(1,2)))));
pkxy=[kx' ky'];
L=[L pkxy];
end
%% Making shorelines
shorelineslength = length(Shorelines);
if mod(shorelineslength,2) == 0
sl2 = shorelineslength/2;
elseif mod(shorelineslength,2) == 1
shorelineslength = shorelineslength-1;
sl2 = shorelineslength/2;
end
k=1; % acquiring the cutting line
for i=2:2:shorelineslength
xi=Shorelines(i,1);
yi=Shorelines(i,2);
xj=Shorelines(i+1,1);
yj=Shorelines(i+1,2);
a1=[xi,xj];
b1=[yi,yj];
Interm(k,1)= xi;
Interm(k,2)= yi;
Interm(k,3)= xj;
Interm(k,4)= yj;
k=k+1;
end
L2=[0 0];
for r=2:1:sl2 % plotting Shoreline along with a segment to disregard.
xn1=[Interm(r,1) Interm(r,3)];
yn1=[Interm(r,2) Interm(r,4)];
plot(Interm(r,1),Interm(r,2),'.');
plot(Interm(r,3),Interm(r,4),'.');
hold on
if r<sl2
xn2=[Interm(r,3) Interm(r+1,1)];
yn2=[Interm(r,4) Interm(r+1,2)];
line(xn2,yn2);
end
line(xn1,yn1)
% plot(xn1(1),yn1(1),'g*') % just checking
L2=[L2;xn1(1) yn1(1)];
hold on
end
%%Write the elevation
z0 = Shorelines(1:transectslength,3);
%% Transect segments and their interecting points with the shoreline
L2(1,:)=[]; % L2 contains all points of the sea shore line .
L2nx=L2(:,1);
L2ny=L2(:,2);
Xp1=[0 0];
Xp2=[0 0];
for k=1:1:size(L,2)
L1=L{k};
L1nx=L1(:,1);
L1ny=L1(:,2);
[x0n,y0n]=intersections(L2nx,L2ny,[L1nx(1) L1nx(end)],[L1ny(1) L1ny(end)]);
x0n=x0n';y0n=y0n';
% expecting 1 and only 1 intersection point from each segment on seashore line, otherwise cell required.
plot(x0n(1),y0n(1),'bd');
% plot(x0n(2),y0n(2),'rd') %If there is another one, which is not ideal
x0n(1) = round(x0n(1)*100)/100; y0n(1) = round(y0n(1)*100)/100;
Xp1=[Xp1;x0n(1) y0n(1)]; % blue intersectionsl curved sea shore
% Xp2=[Xp2;x0n(2) y0n(2)]; % red intersections, approximation of sea shore wth additional straight segment.
end
Xp1(1,:)=[]; %Xp2(1,:)=[];
Xp3 = [Xp1 z0];
%% Create a Excel sheet and copy data
xlswrite('intersection_of_dubaim.20210212.gmt1200.autocad.csv',Xp3)
excelFileName='intersection_of_dubaim.20210212.gmt1200.autocad.csv';
header={'Easting(m)','Northing(m)','Elevation(m)'};
xlswrite(excelFileName,header);
% csvwrite('intersection_of_dubaim.20171105.gmt0335.autocad_1.csv',Xp2)
%% Graph visual representation
grid on
xlabel('Easting')
ylabel('Northing')
[icondata,iconcmap] = imread('images.jpg');
h=msgbox('Operation Completed!',...
'Success','custom',icondata,iconcmap);
  2 comentarios
KSSV
KSSV el 2 de Jun. de 2021
What is function intersections ?
Akhil Narayanan
Akhil Narayanan el 2 de Jun. de 2021
Hi,
I am trying to plot line transects on a curved line joined with points I have extracted earlier. I'll attach the figure I obtained with the same program. I just need an output csv with coordinates of intersection points.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Productos


Versión

R2013a

Community Treasure Hunt

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

Start Hunting!

Translated by