我正在创建一个matlab脚本,稍后将导入到solidworks中。我需要帮助存储循环方程中的值。下面是代码。我想创建三维椭圆,沿z轴间隔开d,半径减小。如何存储输入的数据,然后3D绘制数据?
% 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
答案 0 :(得分:0)
您将需要使用数值数组或单元格数组来存储循环内部的值。我们首先要初始化数组以将数据存储在循环之外,然后通过循环每次迭代填充它们。以下是我正在谈论的内容的粗略概念。
% 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
在循环的不同迭代中有不同的大小(看起来不是你的情况),你会想要使用单元格数组而不是数字数组。