can someone help me to write the code ?

3 次查看(过去 30 天)
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by