can someone help me to write the code ?

조회 수: 1 (최근 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 CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by