How do I plot many rows from many matrices made in a loop?

Hello, I need to make an (11,32,8) 3D array from an equation. I figured out how to get around indexing non-integer numbers and using three for loops to fill in the zeros matrix. However, the output gives a (11,8,9) array... I've attached my code for you to look at. Thank you!
if true
% code
end
ns=[1.5:0.01:1.6]';
B=ns./1.335;
l=[65:95];
v=l+0.5;
TEM=zeros(11,31,8);
R=[4.4:0.1:5.1]*10^-6;
hold on
for j=1:length(R)
for i=1:length(B)
for k=1:length(v)
TEM(i,j,k)=(2*pi.*(B(i).*1.335).*R(j)).*((v(k)+(1.8557.*v(k).^(1/3))-(B(i)./sqrt(B(i).^2-1))+(1.0331.*(v(k).^(-1/3)))-(((0.6186.*B(i).^3)./((B(i).^2-1).^(3/2))).*(v(k).^(-2/3)))+0).^-1);
end
end
end
K=TEM
hold off

댓글 수: 1

Did either solution work for you? If so, please accept the answer that solves your problem best.

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

답변 (2개)

Rik
Rik 2018년 4월 22일
Your function looks like you could use meshgrid to generate the matrices that you need.
ns=[1.5:0.01:1.6]';
B=ns./1.335;
l=[65:95];
v=l+0.5;
R=[4.4:0.1:5.1]*10^-6;
[v,B,R]=meshgrid(v,B,R);%[x,y,z] results in length(y)-by-length(x)-by-length(z)
TEM=(2*pi.*(B.*1.335).*R).*((v+(1.8557.*v.^(1/3))-(B./sqrt(B.^2-1))+(1.0331.*(v.^(-1/3)))-(((0.6186.*B.^3)./((B.^2-1).^(3/2))).*(v.^(-2/3)))+0).^-1);

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

질문:

2018년 4월 22일

댓글:

Rik
2018년 4월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by