필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
Luke Radcliff
Luke Radcliff 2016년 8월 2일
댓글: Walter Roberson 2016년 8월 3일
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

답변 (1개)

Walter Roberson
Walter Roberson 2016년 8월 3일
No.
You should be looking at cell arrays.
  댓글 수: 2
Luke Radcliff
Luke Radcliff 2016년 8월 3일
how would I do it using cell arrays, aren't cell arrays used to store data already found?

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

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by