How can I make a matrix of 35,486 rows 1 column.

Dear all, I want to make a matrix of 35,486 rows and single column, with first 358 row's element is equal to 1, next 359 elements is equal to 2, next 359 elements is equal to 3, next 358 elements is equal to 4 and so on. Value of elements reaches up-to 100 in last elements. Any one please tell me idea.

8 Comments

Do you have some pattern for when the run is 358 rows or 359 rows? For a particular run of some value, how are we supposed to know if there are supposed to be 358 of them or 359 of them?
Looks like it's repeating pattern of [358 358 359 359 ...] maybe? Let's see 358.5*100=35850, though, so that's not it.
Bro basically I am working on KNN method and I have to make a group vector with different elements and there is no such a specific pattern. Pattern is irregular. I was asking if there we may use different loops for each elements and then combine all these vectors in a single vector.
Well however you're finding the number of row elements for the numbers between 1:100;
just use the Concatenation expressions;
X = [];
spacings = [358 359 359 358 ...]
for index =1:length(spacings) %probably 100
X = [X;index*ones(spacings(index),1)];
end
not the most efficient way but if you don't previously know your spacings you cannot preallocate your matrix (or is 35486 a known value where the spacings all add up to that?). This method will also allow you to determine your spacings right before you concatenate it to the previous element.
joseph bro please reread the question. I want to make a vector like this[1;1;1;(upto359 rows);2;2;2;(upto358 rows);3;3;3;(upto346 rows); similarly upto 100 and there in no particular pattern for the number of rows having same elements (e.g. 1 or 2 or 3).
... there in no particular pattern for the number of rows...
Well, there has to be some generating pattern or you're stuck. Now mayhaps that pattern is generated via a call to randi or somesuch, but there's gotta' be something. The 'puter can't just pluck it from the aether, unfortunately.
isn't that was i gave you for X? the Spacings is what you determine. I suggested that since you do not have predetermined spacings the you can just concatenate them together.
Now reading it again with fuzzy eyesight are you asking how to generate the random segments? There has been a few recent posts about random number generation that all add up to a defined total. I forget the function or file exchange name but that function could/would generate 100 entries that add up to 35486, then go do what i did above and loop through those entries.
dear, I am still unable to generate a matrix of my choice... :P

Sign in to comment.

 Accepted Answer

More Answers (0)

Categories

Tags

Asked:

on 25 Jun 2014

Commented:

on 26 Jun 2014

Community Treasure Hunt

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

Start Hunting!