Converting MATLAB code to AutoCAD
23 次查看(过去 30 天)
显示 更早的评论
I am new to MATLAB. I have been trying to convert the code to excel, so I can convert that into autocad, but nothing seems to be working. It is possible to do because I need it for school and past students have done it. This is my code:
t = linspace(0, 2*pi, 201); % this is used to create 201 evenly spaced
% points between 0 and 2pi.
r = sqrt(abs(7*sin(5*t))); % 7 controls the size of the shape.
% 5 controls the amount of petals on each
% side.
% abs is used to ignore all imaginary
% values.
% sin and sqrt are used to give a lower
% value.
[x, y] = pol2cart(t, r); % this command transforms corresponding elements of
% the polar coordinate arrays of theta and ro to 2-D
% cartesian coordinates.
z = 3 * (x.^2 + y.^2); % The (x.^2 + y.^2) is used to control how curved
% up the flower is. The (3) controls the size of
% the flower.
% Plotting the 3D surface
figure(1); % this is used to create a new figure window
fill3(x, y, z, 'c'); % this is used to plot on a 3-D axis.
% the c is used to fill the shape with a cyan color.
grid on; % this is used to show gridlines on the plot.
% Creating a triangulation object
tri = delaunay(x(:), y(:)); % Triangulate the surface
% Save as an STL file
vertices = [x(:), y(:), z(:)]; % Create vertices matrix
stlwrite(tri,'flower.stl'); % Save as an STL file using triangulation objectt = linspace(0, 2*pi, 201); % this is used to create 201 evenly spaced
% points between 0 and 2pi.
r = sqrt(abs(7*sin(5*t))); % 7 controls the size of the shape.
% 5 controls the amount of petals on each
% side.
% abs is used to ignore all imaginary
% values.
% sin and sqrt are used to give a lower
% value.
[x, y] = pol2cart(t, r); % this command transforms corresponding elements of
% the polar coordinate arrays of theta and ro to 2-D
% cartesian coordinates.
z = 3 * (x.^2 + y.^2); % The (x.^2 + y.^2) is used to control how curved
% up the flower is. The (3) controls the size of
% the flower.
% Plotting the 3D surface
figure(1); % this is used to create a new figure window
fill3(x, y, z, 'c'); % this is used to plot on a 3-D axis.
% the c is used to fill the shape with a cyan color.
grid on; % this is used to show gridlines on the plot.
i have since then produced the following code, but when I try to open it with excel, an error comes up.
t = linspace(0, 2*pi, 201); % 201 evenly spaced points between 0 and 2pi
r = sqrt(abs(7*sin(5*t))); % Polar coordinates
[x, y] = pol2cart(t, r); % Convert polar to Cartesian coordinates
z = 3 * (x.^2 + y.^2); % Calculate z coordinates
data = [x(:), y(:), z(:)]; % Create a matrix where each row is [x, y, z]
filename = 'flower_data.xlsx'; % Define the filename
writematrix(data, filename); % Write data to Excel
the error is:
excel cannot open the file 'flower_data.xlsx' because the file format or file extension is not valid. verify that the file has not been corrupted and that the file extension matches the format of the file
can anyone please help?
4 个评论
Pat Gipper
2024-5-17
I can't help you on Autocad questions, and suggest they are best posed on the Autodesk community website.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!