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!