how to save result in continue way in column
1 view (last 30 days)
Show older comments
every time my out put put result is ( N by 1) and i want save the result for every time into column.
2 Comments
Answers (1)
Mathias
on 4 Feb 2020
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 Comments
Mathias
on 4 Feb 2020
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
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!