How to store values in matrix form for differn iteration

11 次查看(过去 30 天)
I am having 7 decimal input data. This data varies for 500 iteration. Now, I need to store the 7 input data obtained in each iteration in a matrix form of 500*7. Thank you in advance.
For example:
A= [6 3 4 5 2 7 1]
Expected output:
[1 3 7 5 6 4 2 % iteration 1
2 4 7 6 5 3 1 % iteration 2
.
.
.
.
7 4 5 1 6 3 2 %iteration 500]
  4 个评论
Dyuman Joshi
Dyuman Joshi 2023-1-29
"Actually my requirement is, "
Then mention it clearly in the question. What your requirement is quite different from what your question asks.
"Now, I need to split this array into 500*7 matrix"
How do you want to split the array?
ASHA PON
ASHA PON 2023-1-29
I am already having array (3500 element) with me. Just, I want to convert it to a matrix of 500*7. That is first 7 element from my array has to be in first row of new matrix. The eigth to fourteenth element from my array has to come in second row of matrix. Then, fifteenth to twenty first elemnt from my array has to come in third row of matrix. Like wise, i will have 500 rows and 7 columns in my final matrix

请先登录,再进行评论。

采纳的回答

Dyuman Joshi
Dyuman Joshi 2023-1-29
Use reshape()
%in case of row array
x=1:3500;
y=reshape(x,7,500)'
y = 500×7
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
%in case of column array
a=(1:3500)';
b=reshape(a,7,500)'
b = 500×7
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70

更多回答(1 个)

Jan
Jan 2023-1-29
编辑:Jan 2023-1-29
A = [6 3 4 5 2 7 1];
Collected = zeros(500, 7);
for k = 1:500
A = rem(A + randi([0, 100], 1, 7), 10); % A random test function
Collected(k, :) = A;
end
" I am having an array stored with 3500 elemnts. Now, I need to split this array into 500*7 matrix.":
X = rand(1, 3500);
Y = reshape(X, 500, 7);
% Or:
Y = reshape(X, 7, 500).';

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by