how to solve Index exceeds the number of array elements (1).

20 ビュー (過去 30 日間)
Sam
Sam 2019 年 7 月 23 日
コメント済み: Sam 2019 年 7 月 23 日
Hi guys, I'm writing a code for simulink model auto generation . But when i run code, it popup this error . How can i solve this problem.
Index exceeds the number of array elements (1).
Error in Create_topology (line 42)
hmp(k) = add_line(mdl,htp{k-1}.RConn(2),htp{k}.LConn(1),'autorouting','on');
open_system('Coil_Architecture');
mdl = 'Coil_Architecture/Coil';
h = find_system(mdl,'FindAll','on','Name','Coil');
Num_Turns = 100 ;
set(h,'Num_Turns',num2str(Num_Turns));
ht = zeros(Num_Turns,1);
hmp = zeros(Num_Turns,1);
htp = cell(Num_Turns,1);
for k = 1:Num_Turns
nk = num2str(k);
% add turn
ht(k) = add_block('Unit_Turn/Turn_1', [mdl,'/Turn_',nk]);
posc = get(ht(k),'Position');
set(ht(k),'Position',posc + [0 30*(k-1) 0 30*(k-1)]);
% get port handles
htp{k} = get(ht(k),'PortHandles');
% connect turn to turn
if k > 1
hmp(k) = add_line(mdl,htp{k-1}.RConn(2),htp{k}.LConn(1),'autorouting','on');
end
end
  2 件のコメント
Sulaymon Eshkabilov
Sulaymon Eshkabilov 2019 年 7 月 23 日
Hi,
could you also post your complete model: Coil_Architecture to simulate and find out more specific details of your err message?
Sam
Sam 2019 年 7 月 23 日
Hi,
thanks for your answer .
i've already up loaded the whole model.

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

採用された回答

David K.
David K. 2019 年 7 月 23 日
What this error is saying is that at some point in that line you are exceeding the number of elements in an array. The (1) is indicating that the actual number of elements in the array is 1.
My guess is that htp{k-1}.Rconn(2) may only have a length of 1.
If it is not that, right before the line display each of your variables and see that they are what you expect them to be.
Hope this helps
  5 件のコメント
David K.
David K. 2019 年 7 月 23 日
Just did so, appears the issue you mentioned is solved by changing
htp{k-1}.RConn(2)
to
htp{k-1}.RConn(1)
Since the struct appears that RConn and LConn are single variables and so there is no .RConn(2). I could not get it working since for me it now said the Turn_1 block could not be added but I expect that may just be my stuff for now. But the indexing issue is gone.
Sam
Sam 2019 年 7 月 23 日
Thanks a lot bro! It worked! By the way you can delete the 2 Turn Blocks in the Coil SubSystem and run the m file again, it should work like the Pic below.Coil.png

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgrammatic Model Editing についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by