How do I plot many rows from many matrices made in a loop?
Ältere Kommentare anzeigen
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 Kommentar
Rik
am 25 Apr. 2018
Did either solution work for you? If so, please accept the answer that solves your problem best.
Antworten (2)
Walter Roberson
am 22 Apr. 2018
TEM(i,k,j) = ...
Rik
am 22 Apr. 2018
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);
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!