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

1 view (last 30 days)
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

Fangjun Jiang
Fangjun Jiang on 26 Apr 2021
Start with this
[x,y,z]=meshgrid(1:4,1:4,1:4);
data=[x(:),y(:),z(:)]
  8 Comments
Shahid Said
Shahid Said on 29 Apr 2021
Edited: Shahid Said on 29 Apr 2021
[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.
Fangjun Jiang
Fangjun Jiang on 29 Apr 2021
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)

Shahid Said
Shahid Said on 28 Apr 2021
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.

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!