how to save result in continue way in column
조회 수: 1 (최근 30일)
이전 댓글 표시
every time my out put put result is ( N by 1) and i want save the result for every time into column.
댓글 수: 2
답변 (1개)
Mathias
2020년 2월 4일
You can add lines:
to arrays with index (end+1) --- multiple: (end+1 : end+length())
to tables with function height() +1
also cat(1, ...) or vertcat() should work on both and can be used for multiple lines or vectors
댓글 수: 2
Mathias
2020년 2월 4일
Its hard to understand your intention completely but maybe you can find a solution in this code.
You can operational add the force values to a zero vector with '+' or
add/concatenate the force vector to the zero vector
% dof function
function y = dof(a,b)
y = a+b;
function to_solve
% example variables
ne = 3;
Ee1 = 2;
Ee2 = 3;
Ee3 = 5;
m1 = 2;
m2 = 3;
m3 = 5;
acce = rand(4,2);
N = 3;
% code
for j = 1:1:4
for i = 1:ne
Ecc = eval(['Ee',num2str(i)]);
acc = [0.3*acce(j,2); acce(j,2); 0; Ecc.*(acce(j,2))'; 0.3*acce(j,2); acce(j,2); 0; Ecc.*(acce(j,2))'];
mas = eval(['m',num2str(i)]); %% calling global elemental mass matrix
eval(['force',num2str(i),'=mas*acc']);
end
FG = []; %%%%%-------ASSEMBLE FORCE VECTOR--------
% FG = zeros(N,1);
m = 5;
for n = 1:1:ne %Calling elements
for i = 1:1:8
d2 = dof(n,m+i-1); % Calling degree of freedom for second node
force = eval(['force', num2str(n)]); % Calling elemental force vector
%% == original ==
% FG(d2,1) = FG(d2,1) + force(i,1); % calling element of the elemental force vector and adding to global force vector
%% == add values at position d2 and trailing ==
if d2 > length(FG)
FG(end+1:d2,1) = 0;
end
FG(d2,1) = FG(d2,1) + force(i,1);
%% == add vector ==
% FG = vertcat(FG, force(i,1)); % calling element of the elemental force vector and adding to global force vector
end
end
end
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!