How can I make a matrix of 35,486 rows 1 column.
Mostrar comentarios más antiguos
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 comentarios
Image Analyst
el 25 de Jun. de 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
el 25 de Jun. de 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
el 26 de Jun. de 2014
Joseph Cheng
el 26 de Jun. de 2014
Editada: Joseph Cheng
el 26 de Jun. de 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
el 26 de Jun. de 2014
dpb
el 26 de Jun. de 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
el 26 de Jun. de 2014
Editada: Joseph Cheng
el 26 de Jun. de 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
el 26 de Jun. de 2014
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!