For Loop - Extract Data

17 ビュー (過去 30 日間)
Sergio Orasch
Sergio Orasch 2020 年 11 月 12 日
コメント済み: Mathieu NOE 2020 年 11 月 12 日
Hello guys,
I have a function in a for loop and I want to get different values for different timestamps. In order to plot the results, I need the values from the for loop. The function fy gives me a [4,1] matrix and all I want is a "result" matrix with all values from the loop. I know that the dimensions do not fit, but I can't come up with a solution. Thanks for helping!
CODE
fy = @(t) (V*expm(D.*t)*inv(V))*x0;
for i = 1:20
y(i) = fy(i);
end
ERROR
Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
  1 件のコメント
Mathieu NOE
Mathieu NOE 2020 年 11 月 12 日
for i = 1:20
y(:,i) = fy(i);
end

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

回答 (1 件)

Ameer Hamza
Ameer Hamza 2020 年 11 月 12 日
You can insert the returned values in colums. For example
fy = @(t) (V*expm(D.*t)*inv(V))*x0;
y = zeros(4, 20);
for i = 1:20
y(:, i) = fy(i);
end

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by