how to add array after the iteration
2 次查看(过去 30 天)
显示 更早的评论
i have two array which are used in the for loop and after iteration of for loop one array will be empty and another array have some values.after second iteration first array have some value and another array will be empty.empty array have not a length but valued array always contain same length. now i wish to add both array if it have value until iteration will be over.after all iteration over then i get total of these array which contain values.
for i=1:4
dist1=[];
dist2=[];
if i>=2 &&i<=4
for i3=1:length(XY)
X12=horzcat([XY12{i-1}]);
Y12=horzcat([XY12{i}]);
X1=X12(i,1);
Y1=X12(i,2);
X2=Y12(i,1);
Y2=Y12(i,2);
E_coord=[X1,Y1;X2,Y2];
Dcoord=pdist(E_coord,'euclidean');
dist1(i)=Dcoord;
end
else
for i=1:length(XY)
X10=XY(i,3);
Y10=XY(i,4);
X11=Xx(i);
Y11=Yy(i);
ECOORD=[X10,Y10;X11,Y11];
DCOORD=pdist(ECOORD,'euclidean');
dist2(i)=DCOORD;
end
end
d=[dist2]'
d=[dist1]'
now i wish to add the dist1 and dist2 if it contain values otherwise if it has not values then doesn't add these array. and plz give me short solution
thanks in advance
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!