For loop in Simulink
50 ビュー (過去 30 日間)
古いコメントを表示
Hi everyone,
I need to convert the following code to a SIMULINK model:
T = [2; 21; 22; 27; 27; 21; 18; 21; 26; 36];
for i = 1:10
C = T(i+1)/T(i);
end
I have used For Iterator Subsystem but I don't know how to apply the i variable to the model. The image of the model is attached herewith. Your help will be very much appreciated.
Mehdi
1 件のコメント
Carsci
2015 年 1 月 19 日
The question is lacking some boundary information for the case N=10. Specifically the calculation can be done for i = 1 : 9 or for i = 1 : 10. If N = 10 is required what is the value of T(i+1) to be used?
採用された回答
Carsci
2015 年 1 月 19 日
Here is a SIMULINK model that uses an Index Vector block with one-based indexing to get the ith data from T. Another Index Vector block gets the (i+1)th data using the zero-indexing option.
I used an Assignment block is used to create C as a vector of the same size as T.
The For Iterator is specified as i = 1:9 so the last value of C does not get updated but retains the initial value of 36 loaded from T at the start of the simulation.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!