Borrar filtros
Borrar filtros

Is it possible to have a for-loop return multiple column vectors?

2 visualizaciones (últimos 30 días)
Luke Radcliff
Luke Radcliff el 2 de Ag. de 2016
Comentada: Walter Roberson el 3 de Ag. de 2016
The last for loop for p=1:length(a), Im trying to get multiple column vectors as the answer for b, 100 column vectors to be exact. I keep getting the error number of elements in A and B must be the same. Not sure if it is possible to get 100 column vectors as the answer, but if you can how do I fix the for-loop. Trying to solve a system of equations multiple times with different inputs, Here is my code.
a = linspace(1,24,1e2);
b = linspace(1,30,1e2);
x = linspace(0,2,1e3);
L = 2;
W1 = @(x) a + b*sqrt(sinh(x.^2));
y = zeros(length(a),1);
for k = 1:length(a)
W1 = @(x) a(k) + b(k)*sqrt(sinh(x.^2));
F(k) = integral(@(x) W1(x),0,L);
end
for i = 1:length(a)
W1 = @(x) a(i) + b(i)*sqrt(sinh(x.^2));
d1(i) = integral(@(x) x.*W1(x),0,L);
end
for j = 1:length(a)
d(j) = d1(j)/F(j);
end
A = [1 1
0 L];
for p = 1:length(a)
b(p) = [F(p); F(p)*d(p)];
end

Respuestas (1)

Walter Roberson
Walter Roberson el 3 de Ag. de 2016
No.
You should be looking at cell arrays.
  2 comentarios
Luke Radcliff
Luke Radcliff el 3 de Ag. de 2016
how would I do it using cell arrays, aren't cell arrays used to store data already found?

Iniciar sesión para comentar.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by