Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Creating two row matrices out of any initial matrix that would contain each element inside the initial matrix and the one in the previous column.

2 ビュー (過去 30 日間)
GEORGIOS BEKAS
GEORGIOS BEKAS 2019 年 10 月 19 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I am trying to create two row matices out of an initial matrix. The two row matrices need to contain each element inside the initial matrix and its previous one.
The code is not good, but are there any shortcuts expressed as MATLAB commands, or any ideas to improve my code?
r = [4 5 6; 4 3 2; 1 4 5]
A = zeros(size(r,1)*size(r,2),2)
function A = breakintopieces(r)
A = zeros(size(r,1)*size(r,2),2)
for i = 1:size(r,1)
for j = 1:size(r,2)
A((i*j),1) =A(i,j-1);
A((i*j),2) =A(i,j);
end
end
endfunction
  2 件のコメント
David Hill
David Hill 2019 年 10 月 19 日
If would be helpful if you showed us what you want the output to be based on the input r. I do not understand what you mean by "previous one"
Daniel M
Daniel M 2019 年 10 月 19 日
Don't index into A using i*j, because the entries will not be unique. Use a counter that you initialize to zero outside your loops and increment every iteration.

回答 (0 件)

製品


リリース

R2012a

Community Treasure Hunt

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

Start Hunting!

Translated by