error in solving cell array multiplication

조회 수: 1 (최근 30일)
summyia qamar
summyia qamar 2017년 1월 13일
편집: James Tursa 2017년 1월 13일
how can I do the column multiplication of each cell array with a vector? I have a A= 2 4 2 4 2 3 and a cell array cell with 6x7 double.. I want to multiply row(1) of 6x7 double with A(1), row(2) with A(2)and so on.
  댓글 수: 2
Adam
Adam 2017년 1월 13일
So what exactly is the structure of your cell array? You seem to have a single cell with a 6x7 double matrix in it from what you are saying. Or do you have many cells of size 6x7?
If your data in your cell array is regular and all the same size then you would be far better off using a 3d array instead.
summyia qamar
summyia qamar 2017년 1월 13일
no_of_machines=7;
no_of_cells=3;
No_of_Parts = 6;
demand_period=26;
Demand=[600;550;500;520;620;500];
Capacity_ofmachines=[960 960 960 960 960 960 960];
OP1=[5 0 0 5 0 6 4;5 7 0 0 4 0 6];
OP2=[0 5 4 5 0 0 6;7 0 4 0 5 7 0];
OP3=[5 0 0 4 8 0 0;0 5 7 0 0 0 6];
OP4=[5 0 0 0 7 0 6;0 5 0 6 0 7 0];
OP5=[5 4 0 0 0 6 0;6 7 0 0 5 0 8];
OP6=[0 5 0 0 0 7 6;5 6 0 7 0 4 0];
for n=1:6
Daily_demand(n)=Demand(n)/demand_period;
end
% All combinations of routes for parts
P = [OP1;OP2;OP3;OP4;OP5;OP6];
z = [size(OP1,1) size(OP2,1) size(OP3,1) size(OP4,1) size(OP5,1) size(OP6,1)];
c = [0 cumsum(z(1:end-1))];
a = allcomb(1:z(1),1:z(2),1:z(3),1:z(4),1:z(5),1:z(6));
n = size(a,1);
all_comb_of_routes = cell(1,n);
for k=1:n
for n=1:No_of_Parts
all_comb_of_routes{k} = P(c+a(k,:),:);
end
end
after this step of generating 1x64 cell arrays I want to run loop over each cell of 6X7 size in which the daily_demand 1st element multiply by 1st row of cell, 2nd element of daily_demand multiply by 2nd row and so on for all cell arrays

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

채택된 답변

James Tursa
James Tursa 2017년 1월 13일
편집: James Tursa 2017년 1월 13일
result = cellfun(@(X)bsxfun(@times,Daily_demand(:),X),all_comb_of_routes,'uni',false);
btw, you can replace this code:
for n=1:6
Daily_demand(n)=Demand(n)/demand_period;
end
with simply this:
Daily_demand = Demand / demand_period;
And what is the point of the "for n=1:No_of_Parts" loop? You are using the same variable n here which is used for the outer loop. I don't think you really want to do that.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by