This is the code that I write to find the minimum distance between the points (column A and column B in the data1.xlsx) with the wall (column C and column D in the data1.xlsx) ,but it has errors, who can help me ,thank you so much.

3 views (last 30 days)
This is the code that I write to find the minimum distance between the points (column A and column B in the data1.xlsx) with the wall (column C and column D in the data1.xlsx) ,but it has errors, who can help me ,thank you so much.
clc;
clear all;
A = xlsread('data1.xlsx');
xpoint=A(:,1);
ypoint=A(:,2);
Num1=length(xpoint);
xwoint=A(:,3);
ywoint=A(:,4);
Num2=length(xwoint);
for i=1:1:Num1;
x1=xpoint(i);
y1=ypoint(i);
for j=1:1:Num2;
x2=xwoint(j);
y2=ywoint(j);
distances = sqrt((x2-x1).^2 + (y2-y1).^2);
minDistance(i) = min(distances)*1000;
end
fdata=minDistance;
end
xlswrite('thick.xlsx',fdata,'sheet1');
%%
The below is the errors:
Error using xlswrite (line 220)
Excel returned: Error: Object returned error code: 0x800A03EC.

Answers (1)

Gouri Chennuru
Gouri Chennuru on 22 Jul 2020
Hi,
As per my understanding, data1.xlsx file contains 17722 rows and 4 columns, From the code, it is clear that you are trying to find the distances from one point to every other point in order to calculate the minimum distances and trying to store them in the excel sheet in column fashion but excel has a constraint on the maximum number of columns it can store. This is causing the xlswrite opeartion to fail. Excel has total number of rows as 1,048,576 and total number of columns as 16,384 in a worksheet.
As a workaround, perform transpose for the numeric array fdata in order to store the data row by row fashion say,
fdata = minDistance';% transpose of the numeric array
Run the following code and you will get the results as expected.
clc;
clear all;
A = xlsread('data1.xlsx');
xpoint=A(:,1);
ypoint=A(:,2);
Num1=length(xpoint);
xwoint=A(:,3);
ywoint=A(:,4);
Num2=length(xwoint);
for i=1:1:Num1;
x1=xpoint(i);
y1=ypoint(i);
for j=1:1:630;
x2=xwoint(j);
y2=ywoint(j);
distances = sqrt((x2-x1).^2 + (y2-y1).^2);
minDistance(i) = min(distances)*1000;
end
fdata=minDistance';
end
filename = 'thicknew.xlsx';
xlswrite(filename,fdata);
% writematrix(fdata,filename);
%%
It is not recommended to use xlswrite starting from R2019a. Use writematrix, instead. The writematrix, function have better cross-platform support and performance over the xlswrite function.
So replace xlswrite(filename,fdata); with
writematrix(fdata,filename);
Hope this helps and resolves the issue!

Tags

Community Treasure Hunt

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

Start Hunting!