Not enough input arguments in Matlab R2021b

1 回表示 (過去 30 日間)
Pedro Rodriguez
Pedro Rodriguez 2022 年 7 月 24 日
コメント済み: Pedro Rodriguez 2022 年 7 月 24 日
function [K] = assembly_gl(Ke,gdl_bar,K)
%--Function that assembles the global stiffness matrix for the entire structure
%Ke=Enter the name of the finite element stiffness matrix you want to add
%gdl_bar=Vector containing the degrees of freedom of the finite element
%K=Specify the array in which the assembly will be stored
for igdl=1:4
ifila = gdl_bar(igdl);
for jgdl=1:4
jcolumna = gdl_bar(jgdl);
K(ifila,jcolumna) = K(ifila,jcolumna) + Ke(igdl,jgdl);
end
end
end
%I don't understand why the error comes out: Not enough input arguments.
%I have already entered all the arguments
%Please help me, thank you so much
  2 件のコメント
Chunru
Chunru 2022 年 7 月 24 日
The code above defined the function. How do you call it?
Pedro Rodriguez
Pedro Rodriguez 2022 年 7 月 24 日
編集済み: Pedro Rodriguez 2022 年 7 月 24 日
I saved the script as: untitled.m
Just in case, it is used to assemble, that is, join more than one matrix into a single matrix, so this code should be:
%DOFT=Degrees of freedom of the entire structure
%For example: DOFT=10
K = zeros(size(DOFT))
However I would use this code: K = zeros(size(DOFT)) in the script that executes the function:assembly_gl(Ke,gdl_bar,K)
My goal is to execute the function:assembly_gl(Ke,gdl_bar,K) many times with a for loop, however I just need the function to be able to execute:assembly_gl(Ke,gdl_bar,K) in a .m file
The problem is that I can't run: untitled.m, due to the error: Not enough input arguments, Error in untitled (line 7)

サインインしてコメントする。

採用された回答

VBBV
VBBV 2022 年 7 月 24 日
Ke = randi(4,4); % assume this as FE stiffness matrix to be added
gdl_bar = [2 2 4 4]; % no of DOF for each element in stiffness
K = zeros(size(Ke)); % pre-allocate matrix to store assembly
K = assembly_gl(Ke,gdl_bar,K) % resulting assembled matrix you want
K = 4×4
0 0 0 0 0 9 0 13 0 0 0 0 0 8 0 11
function [K] = assembly_gl(Ke,gdl_bar,K)
%--Function that assembles the global stiffness matrix for the entire structure
%Ke=Enter the name of the finite element stiffness matrix you want to add
%gdl_bar=Vector containing the degrees of freedom of the finite element
%K=Specify the array in which the assembly will be stored
for igdl=1:4
ifila = gdl_bar(igdl);
for jgdl=1:4
jcolumna = gdl_bar(jgdl);
K(ifila,jcolumna) = K(ifila,jcolumna) + Ke(igdl,jgdl);
end
end
end
give input matrix parameters to the function and pre-allocate any matrix used as argument in function
  3 件のコメント
Torsten
Torsten 2022 年 7 月 24 日
編集済み: Torsten 2022 年 7 月 24 日
As you can see, the above code was run in MATLAB Online.
So it seems that something is not correct with your inputs to the function.
Pedro Rodriguez
Pedro Rodriguez 2022 年 7 月 24 日
I have managed to clarify my doubts, thank you very much to VBBV

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by