Getting multiple outputs in one time

1 次查看(过去 30 天)
Sharanya
Sharanya 2022-12-12
回答: Torsten 2022-12-12
I have a function stiff(k), which outputs a matrix. I want to output stiff(k) for k=1 to 20, but I'm only able to do it by writing out each individul k value. Is there more efficient way to do this?

回答(1 个)

Torsten
Torsten 2022-12-12
A = arrayfun(@(k)stiff(k),1:20,'UniformOutput',0)
A = 1×20 cell array
{2×3 double} {2×3 double} {2×3 double} {2×3 double} {2×3 double} {2×3 double} {2×3 double} {2×3 double} {2×3 double} {2×3 double} {2×3 double} {2×3 double} {2×3 double} {2×3 double} {2×3 double} {2×3 double} {2×3 double} {2×3 double} {2×3 double} {2×3 double}
function out = stiff(k)
out = k*[1 2 3;4 5 6];
end

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by