Converting MATLAB code to AutoCAD
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?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? 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? matlab, autocad, excel, convert, .xlsx MATLAB Answers — New Questions