error with number replication in a cell array

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

Guillaume
Guillaume 2014년 11월 15일
Of course, you get an error. You're never going to be able to concatenate a matrix with its kronecker tensor product with another matrix since by definition the size of the product is much larger than the original matrix.
This has nothing to do with cell array. What exactly are you trying to do?
Assume the following example with a matrix:
kron([1;2;3;4], ones(4,1)).
i have a cell array x with lots of matrices and i want this same function to be applied to all matrices within the cell array. This kron function replicates the numbers in a matrix in this example by 4
Guillaume
Guillaume 2014년 11월 15일
편집: Guillaume 2014년 11월 15일
The kron bit is fine. But in your original example you also concatenate horizontally the result with the original matrix. This is only going to work if your other matrix in kron is only one row.
Did you mean to concatenate the matrices vertically instead?
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일

2 개 추천

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개)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

질문:

AA
2014년 11월 15일

편집:

AA
2014년 11월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by