How to store values in matrix form for differn iteration
10 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Dyuman Joshi
le 29 Jan 2023
"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?
Réponse acceptée
Dyuman Joshi
le 29 Jan 2023
Use reshape()
%in case of row array
x=1:3500;
y=reshape(x,7,500)'
%in case of column array
a=(1:3500)';
b=reshape(a,7,500)'
1 commentaire
Stephen23
le 29 Jan 2023
To make the intent clear and avoid bugs, it is best to use actual transpose:
unless the complex conjugate transpose is specifically required:
Plus de réponses (1)
Jan
le 29 Jan 2023
Modifié(e) : Jan
le 29 Jan 2023
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).';
Voir également
Catégories
En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!