Section an array into equal rows and changing simultaneously the values of each section.

1 visualizzazione (ultimi 30 giorni)
I've been trying to section a matrix into equal rows while changing simultaneously the values of each section but I've been stuck for a while now please I need help. Thanks.
  5 Commenti
Princewill Azorom
Princewill Azorom il 3 Ago 2020
Thanks this is exactly how the solution should look like but if the matrix had entirely different elements in each row how exactly am I supposed to make it have this outcome? And then when I change the dimension of the matrix I should still have the same result too. Thanks
dpb
dpb il 3 Ago 2020
Read
doc kron
and experiment with the above...the vector argument to kron() is what gets duplicated; I just used 1:k here; it can be any content of the right size.
The other comments don't make sense -- again, SHOW US WHAT YOU HAVE TO START WITH and then WHAT YOU THINK THE ANSWER SHOULD BE GIVEN THAT INPUT (and why).
Are you to create the array from scratch which the above does or is there some pre-existing array? If the former, you have the solution, all you have to do is decide what you want the tiled input to be.
If the latter, then the problem is as yet undefined because we don't have what the rule is on how to manipulate a starting set of data to what would be an acceptable final result.

Accedi per commentare.

Risposte (1)

Bruno Luong
Bruno Luong il 3 Ago 2020
Initial data
>> M=randi(10,3,4)
M =
1 3 9 4
6 10 3 4
8 8 5 6
Duplicate rows
>> repelem(M,2,1)
ans =
1 3 9 4
1 3 9 4
6 10 3 4
6 10 3 4
8 8 5 6
8 8 5 6
  10 Commenti
dpb
dpb il 6 Ago 2020
You've been given code already that does that -- all you need to do is wrap in a function per the description...homework is generally not solved on the forum by handing out complete solutions but by expecting poster to show work they've done and then receive hints on specific trouble spots...
Your example code above (that I copied below) doesn't fit the problem description -- there's nothing in the problem that says anything at all about there being any random component at all -- the function takes the two size argurments for the output array size and then returns a specifically constructed array of that size.
function T = X(p,m)
n = 3*p;
T = Randi(5,n,m)
end
Princewill Azorom
Princewill Azorom il 7 Ago 2020
Thank you this was helpful in figuring it out even tho it's just a part of the whole. I really do appreciate your efforts.

Accedi per commentare.

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by