can someone help me to write the code ?

1 visualizzazione (ultimi 30 giorni)
Majid
Majid il 13 Dic 2022
Commentato: Majid il 14 Dic 2022
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

Risposta accettata

Torsten
Torsten il 13 Dic 2022
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 Commenti
Torsten
Torsten il 14 Dic 2022
Modificato: Torsten il 14 Dic 2022
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 il 14 Dic 2022
okay , thank you very much

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by