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

2 ビュー (過去 30 日間)
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 2016 年 8 月 3 日
No.
You should be looking at cell arrays.
##### 2 件のコメントなしを表示なしを非表示
Luke Radcliff 2016 年 8 月 3 日
how would I do it using cell arrays, aren't cell arrays used to store data already found?
Walter Roberson 2016 年 8 月 3 日
for p = 1:length(a)
b{p} = [F(p); F(p)*d(p)];
end

サインインしてコメントする。

### カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

### Community Treasure Hunt

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

Start Hunting!

Translated by