필터 지우기
필터 지우기

Converting MATLAB code to AutoCAD

조회 수: 17 (최근 30일)
Josianne
Josianne 2024년 5월 15일
답변: Amish 2024년 5월 27일
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. This is my code:
t = linspace(0,2*pi,201);
r = sqrt(abs(70*sin(5*t)));
[x y]=pol2cart(t,r);
z = 3 * (x.^2 + y.^2);
figure(1)
fill3(x,y,z,'c')
grid on;
can anyone please help?
  댓글 수: 3
Josianne
Josianne 2024년 5월 15일
apologies I copied one of my trials. this is my code that i need to convert
Walter Roberson
Walter Roberson 2024년 5월 15일
Sorry, I do not know how to code a filled 3D surface in Excel.

댓글을 달려면 로그인하십시오.

답변 (1개)

Amish
Amish 2024년 5월 27일
Hi Josianne,
Your code generates a 3D shape using polar coordinates converted to Cartesian coordinates, and then calculates a z value based on x and y. In order to generate an Excel file that can be used in AutoCAD, you can just simply export these x, y, and z coordinates to an Excel file.
Here is how you can modify your code:
% Your original code for generating the shape
t = linspace(0, 2*pi, 201);
r = sqrt(abs(70*sin(5*t)));
[x, y] = pol2cart(t, r);
z = 3 * (x.^2 + y.^2);
% Visualize the shape
figure(1)
fill3(x, y, z, 'c')
grid on;
% Prepare the data for export
dataForExcel = [x', y', z']; % Combine x, y, and z into a single matrix
% Export the data to an Excel file
filename = 'shapeData.xlsx';
writematrix(dataForExcel, filename);
This will create an Excel file named shapeData.xlsx in your current MATLAB working directory.
Finally, you may use AutoCAD's DATAEXTRACTION command to bring the Excel data into your drawing.
The documentation for the writematrix function can be found at: https://www.mathworks.com/help/matlab/ref/writematrix.html.
Hope this helps!

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by