creating matrix with the same size for different variables
1 次查看(过去 30 天)
显示 更早的评论
hello
i want to creat N number of matrix 2x2 from different variabless then plottting the elemnt (2,1)./(1,1) using for loop but it i always get the last matrix only which overwrite all the previous ones.
who can help me please ?
x=linspace(eps,pi/2,200)
D11=1+sin(x)-cos(x);
D12=1-sin(x)-cos(x);
D21=1-sin(x)+cos(x);
D22=1+sin(x)+cos(x);
for i=1:numel(x)
D=0.5.*[D11(1,i) D12(1,i) ; D21(1,i) D22(1,i)];
end
plot(D(2,1)./D(1,1),x)
0 个评论
采纳的回答
Star Strider
2019-3-10
Try this:
x=linspace(eps,pi/2,200);
D11=1+sin(x)-cos(x);
D12=1-sin(x)-cos(x);
D21=1-sin(x)+cos(x);
D22=1+sin(x)+cos(x);
for i=1:numel(x)
D(:,:,i) = 0.5.*[D11(1,i) D12(1,i) ; D21(1,i) D22(1,i)];
end
figure
semilogy(x, squeeze(D(2,1,:)./D(1,1,:)))
grid
Experiment to get the result you want.
0 个评论
更多回答(1 个)
另请参阅
类别
在 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!