我有以下matlab代码:
clc;
clear all;
close all;
format long;
d=717;
r1=60000;
r2=[61043; 62000];
Rx=[0; 10];
Ry=[11.212; 1];
k=-1.000953;
for o=1:1:size(Rx)
i=1;
for rho1=0:17.7:d
for theta=0:10:360;
rho=rho1;
x(i)=rho.*cosd(theta)+(Rx(o)*1000);
y(i)=rho.*sind(theta)+(Ry(o)*1000);
xx(i)=(((x(i))-(Rx(o)*1000))/d);
yy(i)=(((y(i))-(Ry(o)*1000))/d);
l(i)=sqrt(x(i).^2+(y(i)).^2);
c1=1/r1;
s11(i)=c1*(l(i).^2);
s12(i)=1+(sqrt(1-(1+k)*c1*c1*(l(i).^2)));
s1(i)=s11(i)/s12(i); %hyperbola sag
s2(i)=(r2(o)-sqrt((r2(o).^2)-(l(i).^2))); %Best fit sag
m(i)=abs((-s1(i)+s2(i)));
i=i+1;
end
end
dz=m';
xn=xx';
yn=yy';
Z=[dz xn yn];
end
每次迭代for循环后,数组dz
,xn
,yn
和矩阵Z
都会被修改。如何保存每次迭代的输出?
答案 0 :(得分:1)
您可以使用Multidimensional Arrays的概念,如下所示:
private void button1_Click(object sender, EventArgs e)
{
SerialPort port = new SerialPort("COM4", 9600);
port.Open();
byte[] buffer = new byte[2];
port.Read(buffer, 0, 2);
HandleSerialData(buffer);
port.Close();
}
private void HandleSerialData(byte[] respBuffer)
{
string one, two;
char a, b;
a = Convert.ToChar(respBuffer[0]);
b = Convert.ToChar(respBuffer[1]);
one = Convert.ToString(a);
two = Convert.ToString(b);
MessageBox.Show(one + two);
}