Creating data set for location Problem

I want to create an array of 150*150. filled with randomly generated, 15 cells for Distribution center i(1 to 15) and 50 cells for customer j (1 to 50). Then i want to calculate euclidean distance for each customer from each distribution center. Is there any function for creating the mentioned array of 150*150. Any help will be appreciated as I am totally new to this MATLAB world. Thanks!!!

답변 (1개)

Walter Roberson
Walter Roberson 2012년 5월 30일

0 개 추천

centers = -(1:15); %flag them with negative
customers = 1:50; %let them be positive
numzero = 150 * 150 - length(centers) - length(customers); %# empty places
to_scramble = [centers, customers, zeros(1,numzero));
neworder = randperm(length(to_scramble));
scrambled = to_scramble(neworder);
filledmatrix = reshape(scrambled, [150, 150]);
If you really needed a built-in routine to do this, you could construct everything up to to_scramble and then use a routine from the stats toolbox to do sampling without replacement with to_scramble as the population space, and then you would reshape() that result. Hardly seems worthwhile, considering you could combine
scrambled = to_scramble(randperm(length(to_scramble)));
and not have the overhead of the stats routine.

댓글 수: 2

Varun Jain
Varun Jain 2012년 5월 30일
Thanks for the code sir!!
Any suggestion how to find euclidean distance between centers and each customer?
Walter Roberson
Walter Roberson 2012년 5월 30일
Give the coding a try and see what _you_ can do on your assignment.

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

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

질문:

2012년 5월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by