I try to use bsxfun, but maybe it does not suit this purpose.
C = bsxfun(@function,A(AIterator),cell2mat(B(BIterator)))
A is n*6, where the iterator runs on n, and B is a cell with 3*3 doubles (length m). Thanks for the help.

댓글 수: 5

Star Strider
Star Strider 2014년 10월 26일
Please enlighten us!
What do you want to do? (A bit more of your code prior to the line you posted may help explain that.) Include whatever defines ‘AIterator’ and ‘BIterator’
What does ‘function’ do?
If your code is throwing errors, please copy and paste into your Question the complete text of the error messages, and the line that is throwing the error.
UCL student
UCL student 2014년 10월 26일
Iterators loop A and B like colons do.
The error is: Non-singleton dimensions of the two input arrays must match each other.
The function calculates an array based on the 6; and 3*3 doubles.
Hope this helps.
Or with simple loops:
for AIterator = 1:size(A,1)
for BIterator = 1:size(B,1);
outM{AIterator,BIterator} = function(A(AIterator,:), cell2mat(B(BIterator)));
end
end
Jan
Jan 2014년 10월 26일
I'm deeply confused. What is the meaning of:
The function calculates an array based on the 6; and 3*3 doubles.
?? Please post a minimal running example, which demonstrates your problem.
So, simplified:
A = zeros(100,6);
B = zeros(3,3);
celll = cell(28);
for l = 1:28
celll{l} = B;
end
outM = cell(size(A,1),size(B,1));
for AIterator = 1:size(A,1)
for BIterator = 1:size(B,1);
outM{AIterator,BIterator} = blackboxfunc(A(AIterator,:), cell2mat(celll(BIterator)));
end
end
Blackboxfunc is unknown for me, I try to test how to call that (computational time). I even would like to test it using the gpu.

댓글을 달려면 로그인하십시오.

답변 (1개)

Guillaume
Guillaume 2014년 10월 26일

0 개 추천

bsxfun can only return matrices, not cell arrays, and only operates on matrices as well. If your output has to be a cell array, you can't use bsxfun.
Without knowing more about function, the best that you could do is vectorise the inner loop with:
outM(AIterator, :) = cellfun(@(b) function(A(AIterator, :), cell2mat(b), B, 'UniformOutput', false);

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2014년 10월 26일

댓글:

2014년 10월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by