需要帮助在3D matlab中存储值和绘图吗
我正在创建一个matlab脚本,稍后将导入solidworks。我需要帮助存储循环方程中的值。下面是代码。我想在3D中创建椭圆,沿z轴以逐渐减小的半径隔开。如何存储输入的数据,然后用3D打印该数据需要帮助在3D matlab中存储值和绘图吗,matlab,loops,3d,Matlab,Loops,3d,我正在创建一个matlab脚本,稍后将导入solidworks。我需要帮助存储循环方程中的值。下面是代码。我想在3D中创建椭圆,沿z轴以逐渐减小的半径隔开。如何存储输入的数据,然后用3D打印该数据 % 1TotalMesurments prompt={'Enter the number of measurements taken', ... 'Enter the distance between each measurement in inches'} name = 'Ste
% 1TotalMesurments
prompt={'Enter the number of measurements taken', ...
'Enter the distance between each measurement in inches'}
name = 'Step 1 total measurements and distance';
answer = inputdlg(prompt, name);
s= str2double(answer{1}); %Number of measurement
d= str2double(answer{2}); %Distance between each measurement
% 3LoopOfCircumferenceAndWidth
for i=1:s %s is predefined in 1TotalMeasurments
% 2Circumferenceandwidth%
prompt = {'Enter the Circumference of 1st point', ...
'Enter the approximate width of your arm'};
title = 'Circumference and width of arm at first point';
answer = inputdlg(prompt, title);
C = str2double(answer{1}); %Circumference
X = str2double(answer{2}); %width radius value
Y=(((C./(2.*pi))^2).*2)-(X./2)^2; %height radius value
plot(X,Y)
hold on
end
您需要使用数值数组或单元格数组来存储循环内部的值。我们首先要初始化数组以在循环外部存储数据,然后在循环的每次迭代中填充它们。这是我所说的大概意思
% Pre-allocate the array based on the total # of measurements
Cvalues = zeros(s, 1);
Xvalues = zeros(s, 1);
Yvalues = zeros(s, 1);
for k = 1:s
prompt = {'Enter the Circumference of 1st point', ...
'Enter the approximate width of your arm'};
title = 'Circumference and width of arm at first point';
answer = inputdlg(prompt, title);
C = str2double(answer{1}); %Circumference
X = str2double(answer{2}); %width radius value
Y = (((C./(2.*pi))^2).*2)-(X./2)^2; %height radius value
% Assign them to your arrays for storage
Cvalues(k) = C;
Xvalues(k) = X;
Yvalues(k) = Y;
plot(X,Y)
hold on
end
如果
C
、X
和Y
在循环的不同迭代中大小不同(您的情况似乎不是这样),则需要使用单元格数组而不是数字数组。您需要使用数字数组或单元格数组来存储循环内部的值。我们首先要初始化数组以在循环外部存储数据,然后在循环的每次迭代中填充它们。这是我所说的大概意思
% Pre-allocate the array based on the total # of measurements
Cvalues = zeros(s, 1);
Xvalues = zeros(s, 1);
Yvalues = zeros(s, 1);
for k = 1:s
prompt = {'Enter the Circumference of 1st point', ...
'Enter the approximate width of your arm'};
title = 'Circumference and width of arm at first point';
answer = inputdlg(prompt, title);
C = str2double(answer{1}); %Circumference
X = str2double(answer{2}); %width radius value
Y = (((C./(2.*pi))^2).*2)-(X./2)^2; %height radius value
% Assign them to your arrays for storage
Cvalues(k) = C;
Xvalues(k) = X;
Yvalues(k) = Y;
plot(X,Y)
hold on
end
如果C
、X
和Y
在循环的不同迭代中大小不同(您的情况似乎不是这样),那么您可能希望使用单元格数组而不是数字数组