How to multiply a cell array with a matrix
이전 댓글 표시
Ya I have a cell matrix example [1 0;1 0;0 1][0 1;0 1;1 0] and a matrix of 3*5. I want to multiply this cell matrix and the 3*5 matrix. How can I do this thing? What I have done is
for l1=1:ll
for j1=1:jj
for i1=1:ii
out=cellfun(@(y) y*w(i1,j1),x(i1,l1),'un',0)
tot = cellfun(@(y) sum(y(:)), out,'UniformOutput', false);
x1(i1,l1)= cellfun(@(y) sum(y(:)), x(i1,l1),'UniformOutput', false);
end
m(l1,j1)=cellfun(@rdivide,tot,x1(i1,l1),'UniformOutput',false)% avarege cell load
end
end
댓글 수: 4
I presume that in your example of the matrix you meant
w = ...
and not
w(i,j) = ...
as the latter is not valid matlab syntax. I've no idea of the format of x though. I'd have thought it'd be a column (or row) cell array, but in your code it appears to be a 2D cell array.
Each of your logical array is of size 5x2. How do you expect to multiply that with w which is of size 5x7?
Azzi Abdelmalek
2015년 6월 5일
You don't need to post all this big matrix, just post a short example, and what you need. Specify if you are using cell array.
Aryama Mandal
2015년 6월 5일
Abhishek
2025년 3월 3일
Hi, can you please specify which verison of MATLAB did you use?
답변 (1개)
Aravind
2025년 3월 3일
To convert a cell array into a regular array in MATLAB, you can use the "cell2mat" function. Once you have the regular array, you can multiply it with any matrix using the '*' operator for matrix multiplication.
Here's an example:
cellArray = {[1,0;0,1;1,1],[1,1;2,5;1,0]};
regularArray = rand(4,3); % Example matrix
productValue = cell2mat(cellArray) * regularArray; % Perform matrix multiplication
For more details on the "cell2mat" function, you can visit: https://www.mathworks.com/help/matlab/ref/cell2mat.html. Alternatively, you can view the documentation specific to your MATLAB version by entering the following command in the MATLAB command prompt:
doc cell2mat
I hope this helps!
카테고리
도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!