For loop through a cell array
조회 수: 3 (최근 30일)
이전 댓글 표시
Hi, I need to calculate a for loop through a cell array. Each element has 5x5 matrixes. As seen in the code, I need to calculate a for loop in each element of D.
clc
clear all
N=5;
xn=linspace(2,4,N);
yn=xn;
for nx=1:N
for ny=1:N
E1(nx,ny)=xn(nx)*1i+(xn(nx)-yn(ny)^2);
E2(nx,ny)=(xn(nx)+yn(ny))*1i+xn(nx);
end
end
a11=E1.*conj(E1);
a12=E1.*conj(E2);
a21=E2.*conj(E1);
a22=E2.*conj(E2);
A=[a11 a12;a21 a22];
B={E1;E2};
C={conj(E1);conj(E2)};
D=cell(2,2);
for i=1:2
for j=1:2
D{i,j}=B{i}.*C{j};
end
end
댓글 수: 3
Jan
2021년 5월 21일
Your code seems to be fine for this job. So which problem do you want to solve now? In the code you use a {2 x 2} cell. If your real data are {8 x 8} simply change the code to:
D = cell(28, 8);
for i = 1:8
for j = 1:8
D{i,j} = B{i} .* C{j};
end
end
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!