Make Combination form 3 kind of variable and each variable have its own value

Hello,
I would like to create combination of 3 Column as below :
Car Lamp Seat
Car1 Lamp1 Seat1
Car2 Lamp2 Seat2
Car3 Lamp3 Seat3
Car4 Lamp 4 Seat4
until maximum combination
then each variable have it own value.
Car Length Height Weight
Car1 2.03 2.0 1800
Car2 2.30 2.1 1750
Car3 2.40 2.3 1630
Car4 2.10 2.0 1560
Car Length Height Weight
Lamp1 2.03 2.0 1800
Lamp2 2.30 2.1 1750
Lamp3 2.40 2.3 1630
Lamp4 2.10 2.0 1560
and seat also have it own spec.
then i would like to put the combination value into formula row by row.
can someone help me?
im still new in using matlab.
thank you very much.

 Accepted Answer

Start with this
[x,y,z]=meshgrid(1:4,1:4,1:4);
data=[x(:),y(:),z(:)]

8 Comments

Thanks for your reply. If you dont mind, may you see the attachment enclosed.I have made simple explaination. thank you very much for your support.
Add the following code
%%
Car={'a',1;'b',2;'c',3;'d',4};
Lamp={'L1',10;'L2',20;'L3',30;'L4',40};
Seat={'S1',-1;'S2',-2;'S3',-3;'S4',-4};
ExpandData=[Car(data(:,1),:), Lamp(data(:,2),:), Seat(data(:,3),:)]
Thank you.i will update to you after test the code.
clc
clear
[x,y,z]=meshgrid(1:4,1:4,1:4);
data=[x(:),y(:),z(:)];
%%
Car={'C1',24,8.86,9.37,38.65,31.61,280,25,-0.0033,-0.004,0.058,45,0.97;...
'C2',24,8.68,9.37,38.6,32.4,280,25,-0.0034,-0.004,0.057,46.5,0.98;...
'C3',24,8.87,9.42,37.7,31.6,280,25,-0.0032,-0.0041,0.05,44,0.97;...
'C4',24,9.04,9.49,38.65,30.97,280,25,-0.0033,-0.0041,0.059,45,0.97};
Lamp={'L1',10,11;'L2',20,11;'L3',30,23;'L4',40,24};
Seat={'S1',147,32,145;'S2',138,120,140;'S3',400,80,116;'S4',300,150,240};
ExpandData=[Car(data(:,1),:), Lamp(data(:,2),:), Seat(data(:,3),:)]
I already add C5 but the data not expanding still stuck at 64 X 20 cell.I think it should be more.
I think for combination it should be more row.tried to edit some point but no luck.
may you help me put comment for each script line so i will try to understand.
Thanks for your help. I'm really appreciate it.
Change this
[x,y,z]=meshgrid(1:NumberOfCars, 1:NumberOfLamps, 1:NumberofSeats)
[x,y,z]=meshgrid(1:20,1:20,1:10);
data=[x(:),y(:),z(:)]
%%
Cars={'a',1;'b',2;'c',3;'d',4;'5',5;'6',6;'7',7;'8',8;'9',9;'10',10;'11',11;'12',12;'13',13;'14',14;'15',15;'16',16;'17',17;'18',18;'19',19;'20',20};
Lamps={'L1',10;'L2',20;'L3',30;'L4',40;'L5',50;'L6',60;'L7',70;'L8',80;'L9',90;'L10',100;'L11',110;'L12',120;'L13',130;'L14',140;'L15',150;'L16',160;'L17',170;'L18',180;'L19',190;'L20',200};
Seats={'S1',-1;'S2',-2;'S3',-3;'S4',-4;'S5',-5;'S6',-6;'S7',-7;'S8',-8;'S9',-9;'S10',-10};
Tyres = {'S1',-1;'S2',-2;'S3',-3;'S4',-4;'S5',-5;'S6',-6;'S7',-7;'S8',-8;'S9',-9;'S10',-10};
ExpandData=[Car(data(:,1),:), Lamp(data(:,2),:), Seat(data(:,3),:)] (use this OK) but tyre data not appear
Change to this
ExpandData=[Car(data(:,1),:), Lamp(data(:,2),:), Seat(data(:,3),:),Tyre(data(:,4),:)] use this error.I want to include tyre data
I try replace this also error
[x,y,z]=meshgrid(1:NumberOfCar, 1:NumberOfLamp, 1:NumberofSeat, 1:NumberofTyre)
:-(
[x,y,z]=meshgrid(1:20,1:20,1:10,1:10); <------change this
data=[x(:),y(:),z(:)]
%%
%%
%%
Car={'a',1;'b',2;'c',3;'d',4;'5',5;'6',6;'7',7;'8',8;'9',9;'10',10;'11',11;'12',12;'13',13;'14',14;'15',15;'16',16;'17',17;'18',18;'19',19;'20',20};
Lamp={'L1',10;'L2',20;'L3',30;'L4',40;'L5',50;'L6',60;'L7',70;'L8',80;'L9',90;'L10',100;'L11',110;'L12',120;'L13',130;'L14',140;'L15',150;'L16',160;'L17',170;'L18',180;'L19',190;'L20',200};
Seat={'S1',-1;'S2',-2;'S3',-3;'S4',-4;'S5',-5;'S6',-6;'S7',-7;'S8',-8;'S9',-9;'S10',-10};
Tyre ={'S1',-1;'S2',-2;'S3',-3;'S4',-4;'S5',-5;'S6',-6;'S7',-7;'S8',-8;'S9',-9;'S10',-10};
ExpandData=[Car(data(:,1),:), Lamp(data(:,2),:), Seat(data(:,3),:), Tyre(data(:,4),:)] <<<----change this to add 'tyre' data
________________________________________________________________________________
[x,y,z]=meshgrid(1:20,1:20,1:10);<----delete this
data=[x(:),y(:),z(:)];
%%
%%
%%
Car={'a',1;'b',2;'c',3;'d',4;'5',5;'6',6;'7',7;'8',8;'9',9;'10',10;'11',11;'12',12;'13',13;'14',14;'15',15;'16',16;'17',17;'18',18;'19',19;'20',20};
Lamp={'L1',10;'L2',20;'L3',30;'L4',40;'L5',50;'L6',60;'L7',70;'L8',80;'L9',90;'L10',100;'L11',110;'L12',120;'L13',130;'L14',140;'L15',150;'L16',160;'L17',170;'L18',180;'L19',190;'L20',200};
Seat={'S1',-1;'S2',-2;'S3',-3;'S4',-4;'S5',-5;'S6',-6;'S7',-7;'S8',-8;'S9',-9;'S10',-10};
Tyre ={'S1',-1;'S2',-2;'S3',-3;'S4',-4;'S5',-5;'S6',-6;'S7',-7;'S8',-8;'S9',-9;'S10',-10};
[x,y,z]=meshgrid(1:NumberOfCars, 1:NumberOfLamps, 1:NumberofSeats) <<----put here
Try this still cannot run.
sorry for burden you.
If you need adding tyre, you need to add another dimension.
[x,y,z,w]=ndgrid(1:2, 1:3, 1:4, 1:5);
data=[x(:), y(:), z(:), w(:)]

Sign in to comment.

More Answers (1)

I made it !!! Thank you very much.If anything i will ask you later.
[x,y,z]=meshgrid(1:20,1:20,1:10);
data=[x(:),y(:),z(:)]
%%
%%
%%
Car={'a',1;'b',2;'c',3;'d',4;'5',5;'6',6;'7',7;'8',8;'9',9;'10',10;'11',11;'12',12;'13',13;'14',14;'15',15;'16',16;'17',17;'18',18;'19',19;'20',20};
Lamp={'L1',10;'L2',20;'L3',30;'L4',40;'L5',50;'L6',60;'L7',70;'L8',80;'L9',90;'L10',100;'L11',110;'L12',120;'L13',130;'L14',140;'L15',150;'L16',160;'L17',170;'L18',180;'L19',190;'L20',200};
Seat={'S1',-1;'S2',-2;'S3',-3;'S4',-4;'S5',-5;'S6',-6;'S7',-7;'S8',-8;'S9',-9;'S10',-10};
Tyre = xxxxxxx (data)
ExpandData=[Car(data(:,1),:), Lamp(data(:,2),:), Seat(data(:,3),:)]
I want to add Tyre data
I tried below code but it doesnt work.
ExpandData=[Car(data(:,1),:), Lamp(data(:,2),:), Seat(data(:,3),:),Seat(data(:,4),:)]
Thank you for your perusal.

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Products

Release

R2018a

Community Treasure Hunt

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

Start Hunting!