MATLAB: How to store loop value in array arrayincrementalloopMATLAB For …. A=A+1; End %how can i store value A in array Best Answer You need to use an array to store all the values. If values are scalar or vectors of constant length, then you can use simple arrays. If, in each iteration, the result is of variable length, then you will need to use cell arrays. For exampleA = zeros(1, 10)for i = 2:10 A(i) = A(i-1) + 1;endSee the first example here: https://www.mathworks.com/help/matlab/ref/for.html Related SolutionsMATLAB: Save each loop values, without overwriting for i=1:10a(i)=..... %using arrayend Here value will not replace, values save as a(1), a(2).. etc MATLAB: How to store results from loops and put them in matrice 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 arrayfor p=1:10 R(p,1)=[p.*A(:,1) A(:,2) A(:,3)]; Rend At the end of Simulation, R will have all the elements you need. Related QuestionHow to store values from an array to another array using LoopsHow to store strings into arrayArray with vectors as elements
Best Answer