フィルターのクリア

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?
Walter Roberson
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