如何连接循环中的数组?软件

How can I concatenate the arrays in loop ? Matlab

有循环;

for i = 1:n

X_rotate  = X.*cos(i*increment) - Y.*sin(i*increment);
X_rotateh = X_rotate./cos(deg2rad(helix_angle));
Y_rotate  = X.*sin(i*increment) + Y.*cos(i*increment);

Helix     = [X_rotateh(1:K1) ; Y_rotate(1:K1)];
fileID    = fopen('helix_values.txt', 'w');
fprintf(fileID,'%f %f\n ', Helix);
fclose(fileID);
end

XY是行矢量及其大小取决于输入。顺便提一下迭代次数nX[=的大小51=] 和 Y 可以不同。正如我所说,它们取决于输入。

当打开文本文件时,只存在X_rotateh和[=37=最后一次迭代的值]Y_rotate。我需要收集 X_rotatehY_rotate[= 的值50=]first 值到 K1 th 每次迭代两者的值。我尝试使用 cat 命令。它没有给我想要的东西。另一方面,我经常遇到关于数组长度或大小的问题。

这些值应该在文本文件中按顺序排列;

%for first iteration;

X_rotateh(1) Y_rotate(1)

X_rotateh(2) Y_rotate(2)

.

.

X_rotateh(K1) Y_rotate(K1)

%for second iteration;

X_rotateh(1) Y_rotate(1)

X_rotateh(2) Y_rotate(2)

.

.

X_rotateh(K1) Y_rotate(K1)
%so on..

我可以做什么?

提前致谢。

如您所说,文本文件包含上次迭代的结果。这可能是因为您使用 'w' 权限打开文本文件。这会写入新内容,但也会删除文件中先前存储的内容。尝试使用 'a' 权限。这将附加新内容而不删除以前的内容。

fileID = fopen('helix_values.txt', 'a');

您还可以在 MATLAB 中使用 help fopen 命令找到更多详细信息。

如果这能解决问题,请告诉我。