can someone help me to write the code ?

21 ビュー (過去 30 日間)
Majid
Majid 2022 年 12 月 13 日
コメント済み: Majid 2022 年 12 月 14 日
Hi all
i'm trying to execute my program in matlab in order to ckeck results after a number of iteration under two variables B1 and B2, which are two row vectors with same dimension but i will focus only for the first element of each of them, it means i want to do a number of iteration in order to change the first element of each vector,
so i wrote my code as follow : here B1 should be started from 0 and B2 from 1000.
A_100_iteration = cell(51,1);
Result_100_iteration = cell(51,1);
for ib = 1:51
B1(1) = (ib-1)*20;
%code of the first variable
for ib1 = 50:-1 :1
B2(1) = (ib)*20;
%code of the first variable
for n = 1:100
%my program is here
A_100_iteration{ib}=[A_100_iteration{ib},A] ;
Result_100_iteration{ib}=[Result_100_iteration{ib},Result] ; %
end
B1_100_iteration{ib} = [B1_100_iteration{ib},B1];
B2_100_iteration{ib1} = [B2_100_iteration{ib1},B2];
end
end
the code doesn't work as i want, in each time the dimension of each vector has been changed,knowing that when i did same code for only B1 it works well.
any suggestion please

採用された回答

Torsten
Torsten 2022 年 12 月 13 日
A_100_iteration = cell(51,50,1);
Result_100_iteration = cell(51,50,1);
B1_100_iteration = cell(51,50,1);
B2_100_iteration = cell(51,50,1);
for ib = 1:51
B1(1) = (ib-1)*20;
%code of the first variable
for ib1 = 1:50
B2(1) = (51-ib1)*20;
%code of the first variable
for n = 1:100
%my program is here
A_100_iteration{ib,ib1}=[A_100_iteration{ib,ib1},A] ;
Result_100_iteration{ib,ib1}=[Result_100_iteration{ib,ib1},Result] ; %
end
B1_100_iteration{ib,ib1} = [B1_100_iteration{ib,ib1},B1];
B2_100_iteration{ib,ib1} = [B2_100_iteration{ib,ib1},B2];
end
end
  8 件のコメント
Torsten
Torsten 2022 年 12 月 14 日
編集済み: Torsten 2022 年 12 月 14 日
Still not motivated to take the online MATLAB course for free:
?
Only two hours - I think it would help you.
%Generate cell array of row vectors
A_100_iteration = cell(51,1);
for i = 1:51
A_100_iteration{i} = [2 3 4 5 6 7];
end
%Extract last element from each cell
Array_last_element = zeros(51,1);
for i = 1:51
Array_last_element(i) = A_100_iteration{i}(end);
end
Array_last_element
Array_last_element = 51×1
7 7 7 7 7 7 7 7 7 7
Majid
Majid 2022 年 12 月 14 日
okay , thank you very much

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by