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

1 回表示 (過去 30 日間)
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 件のコメント
Princewill Azorom
Princewill Azorom 2020 年 8 月 3 日
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 2020 年 8 月 3 日
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.

サインインしてコメントする。

回答 (1 件)

Bruno Luong
Bruno Luong 2020 年 8 月 3 日
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 件のコメント
dpb
dpb 2020 年 8 月 6 日
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 2020 年 8 月 7 日
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.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by