how to store array

조회 수: 4 (최근 30일)
Ls
Ls 2021년 9월 11일
댓글: Star Strider 2021년 9월 11일
I have
for x=1:5
A=[5*x 0;2*x^2 1]
B=[0;2.55]
Y=A\B
end
How can I store 5 different matrices of 2X1 in excel

채택된 답변

Star Strider
Star Strider 2021년 9월 11일
Try something like this —
xv=1:5;
for k = 1:numel(xv)
x = xv(k);
A=[5*x 0;2*x^2 1];
B=[0;2.55];
Y(:,x)=A\B;
end
Y
Y = 2×5
0 0 0 0 0 2.5500 2.5500 2.5500 2.5500 2.5500
writematrix(Y,'YourFileName.xlsx')
Experiment to get the result you want.
.
  댓글 수: 2
Ls
Ls 2021년 9월 11일
It does not work when xv =0:0.1:3!! What should we change in case of that???
Star Strider
Star Strider 2021년 9월 11일
After I created ‘xv’ I forgot to update the subscript in ‘Y’ (corrected here). My apologies.
xv=0:0.1:3;
for k = 1:numel(xv)
x = xv(k);
A=[5*x 0;2*x^2 1];
B=[0;2.55];
Y(:,k)=A\B;
end
Warning: Matrix is singular to working precision.
Y
Y = 2×31
NaN 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 NaN 2.5500 2.5500 2.5500 2.5500 2.5500 2.5500 2.5500 2.5500 2.5500 2.5500 2.5500 2.5500 2.5500 2.5500 2.5500 2.5500 2.5500 2.5500 2.5500 2.5500 2.5500 2.5500 2.5500 2.5500 2.5500 2.5500 2.5500 2.5500 2.5500
figure
plot(xv, Y, '.-')
grid
Beyond that, it works, however with any element of ‘xv’ being 0, there is going to be a NaN result, because the‘Y’ calculation results in a 0/0 operation, that result (or in a few similar situations) will be NaN.
.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by