how to store array

2 vues (au cours des 30 derniers jours)
Ls
Ls le 11 Sep 2021
Commenté : Star Strider le 11 Sep 2021
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

Réponse acceptée

Star Strider
Star Strider le 11 Sep 2021
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 commentaires
Ls
Ls le 11 Sep 2021
It does not work when xv =0:0.1:3!! What should we change in case of that???
Star Strider
Star Strider le 11 Sep 2021
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.
.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Tags

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by