How to store results from loops and put them in matrice

1 Ansicht (letzte 30 Tage)
Jmed
Jmed am 28 Mai 2019
Kommentiert: Stephen23 am 29 Mai 2019
I have this propostion:
clear all, clc
X=[0 1], Y=[0 1], Z=[0 1];
A=allcomb(X, Y,Z);
for p=1:10
R=[p.*A(:,1) A(:,2) A(:,3)];
R
end
I want that results of each iteration will be stored in matrice

Akzeptierte Antwort

Raj
Raj am 28 Mai 2019
Bearbeitet: Raj am 28 Mai 2019
Just pre define R as an empty array and use it inside the loop with suitable indexing. Something like this:
R=zeros(10,1); % Pre define R as zero array
for p=1:10
R(p,1)=[p.*A(:,1) A(:,2) A(:,3)];
R
end
At the end of Simulation, R will have all the elements you need.
  1 Kommentar
Jmed
Jmed am 29 Mai 2019
Many thanks Raj. I just mention that the Matrice R returns only the values 0. And Normally it is 80-by-3. R=zeros(80,3);

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by