cell to double problem for loop includes cellarrays.

1 回表示 (過去 30 日間)
sermet
sermet 2014 年 5 月 23 日
回答済み: Andrei Bobrov 2014 年 5 月 23 日
A=[1 1;2 2;3 3;4 4;5 5;6 6;7 7;8 8;9 9;10 10;11 11;12 12;13 13]
B=[3;4;3;3]
C=[1;2;3;4;5;6;7;8;9;10;11;12;13]
for k = 1 : length(B)
if k == 1
row1 = 1
else
row1 = 1 + sum(B(1:k-1))
end
row2 = sum(B(1:k))
x{k} = A(row1:row2, :)
y{k}= C(row1:row2, 1)
end
%I wanna add (inv(x'*x)*x'*y) for each k into loop. Problem is x and y are cell in the loop.

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 5 月 23 日
Replace x by x{k}
inv(x{k}'*x{k})*x{k}'*y{k}

その他の回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2014 年 5 月 23 日
xc = mat2cell(A,B,size(A,2));
yc = mat2cell(C,B,size(C,2));
out = cellfun(@(a,b)(a'*a)\a'*b,xc,yc,'un',0);

カテゴリ

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