How can I make a matrix of 35,486 rows 1 column.
Show older comments
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
Image Analyst
on 25 Jun 2014
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?
dpb
on 25 Jun 2014
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.
Zishan
on 26 Jun 2014
Joseph Cheng
on 26 Jun 2014
Edited: Joseph Cheng
on 26 Jun 2014
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.
Zishan
on 26 Jun 2014
dpb
on 26 Jun 2014
... 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.
Joseph Cheng
on 26 Jun 2014
Edited: Joseph Cheng
on 26 Jun 2014
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.
Zishan
on 26 Jun 2014
Accepted Answer
More Answers (0)
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!