필터 지우기
필터 지우기

How to generate matrix from iterations?

조회 수: 4 (최근 30일)
Safia
Safia 2023년 1월 11일
댓글: Safia 2023년 1월 11일
Hello !
In my program, I have two vectors V1 and V2 as follows:
V1 =[0 20 60 80 100]
V2 =[20 60 80 100]
i want to run my program for V2 and each element of V1, it means
i run my code 10 iterations for each element
V2=20 , V1= 0
V2=60 , V1=0
V2=80 , V1 =0
V2=100 , V1=0
after this
V2=20 , V1=20
V2=60 , V1=20
V2=80 , V1 =20
V2=100 , V1=20
until all the elements of V1 are completed, each time I get a result, I want to put it in the matrix to see the result of 10 iterations of each association between elements of V1 and V2.
thanks in advance

답변 (1개)

Torsten
Torsten 2023년 1월 11일
편집: Torsten 2023년 1월 11일
V1 =[0 20 60 80 100];
V2 =[20 60 80 100];
itermax = 10;
for i = 1:numel(V1)
v1 = V1(i);
for j = 1:numel(V2)
v2 = V2(j)
for iter = 1:itermax
% Calculate some quantity depending on v1 and v2 and save it as result(i,j)
end
end
end
  댓글 수: 1
Safia
Safia 2023년 1월 11일
@Torsten Hi! the code you provided doesn't work in my code case because i have many for loops and the final result does not directly related to V1 and V2 ,So I try to explain more about the method I want to use to make it easier.
i keep the vector V1.
for V2 i generated with same dimension of V1 starting from the first element as follow
V1 =[0 20 60 80 100];
V2 =[20 20 20 20 20];
i did 10 iterations , i wrote the result in form of cell (5 cell) in each cell 10 results of 10 iterations.
Now i want to change V2
V1 =[0 20 60 80 100];
V2 =[60 60 60 60 60];
here V1 and V2 are two examples so if the vector have less elements i can do it , but the problem in my real case V1 and V2 have 50 elements, so i need a loop to replace each time V2 and the result will be saved in cell like i did exactly with one value.

댓글을 달려면 로그인하십시오.

카테고리

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