how to store array

2 visualizaciones (últimos 30 días)
Ls
Ls el 11 de Sept. de 2021
Comentada: Star Strider el 11 de Sept. de 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

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by