error with number replication in a cell array

6 ビュー (過去 30 日間)
AA
AA 2014 年 11 月 15 日
編集済み: AA 2014 年 11 月 25 日
Hi guys, mx is a 100x61 cell array. I want to replicate the numbers of all cells in the cell array with the following formula but i get the following error:
n=61
for f = 1:n
for k=1:length(mx)
myCells{k,f} = [mx{k,f} ((kron([mx{k,f}], ones(4,1))))];
end
end
Error using horzcat Dimensions of matrices being concatenated are not consistent.
I tried many things to correct it but it didnt help. can anyone help.
  5 件のコメント
AA
AA 2014 年 11 月 15 日
Thanks. The cell array is not one row but consists of 100 rows and 61 columns. Each of these cells is a matrix with many columns and rows. is there an alternative
Guillaume
Guillaume 2014 年 11 月 15 日
You can't concatenate horizontally matrices with a different numbers rows, no matter what.
Since your kron creates a matrix with the same numbers of columns, you can do the concatenation vertically as in my answer.
Once again, this has nothing to do with cell arrays and the size of the cell array is irrelevant. It's simply to do with matrix concatenation.

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

採用された回答

Guillaume
Guillaume 2014 年 11 月 15 日
This is possibly what you want:
for ...
for ...
mycells{k, f} = [mx{k,f}; kron(mk{k, f}, ones(4, 1))];
end
Note that the bounds of your loops don't look right. You could just replace the loops with a cellfun
mycells = cellfun(@(m) [m; kron(m, ones(4, 1)], mx, 'UniformOutput', false);
  1 件のコメント
AA
AA 2014 年 11 月 25 日
編集済み: AA 2014 年 11 月 25 日
n=61
for f = 1:n
for k=1:length(mx)
mxx{k, f} = [kron(mx{k, f}, ones(60, 1))];
end
end

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by