function handles to save data

2 views (last 30 days)
Max Müller
Max Müller on 19 Aug 2014
Answered: Geoff Hayes on 19 Aug 2014
I want to save the Output for every round my loop takes. The Problem; I need an handle and my m-file has no Objects. The Question: How do i define a handle which i can use to store my data.
  3 Comments
Max Müller
Max Müller on 19 Aug 2014
ok, help me pls. I store each loop "round" in 1 array row. So how do i get an empty 1x9 Array ?
Max Müller
Max Müller on 19 Aug 2014
i will go home, sleep 12hours and work again tomorrow. thanks

Sign in to comment.

Accepted Answer

Geoff Hayes
Geoff Hayes on 19 Aug 2014
Max - try the following. Suppose the output from one iteration of your loop is a 1x9 vector, and that there are 25 iterations. That means we need a 25x9 matrix:
maxIters = 25;
allData = zeros(maxIters,9);
for k=1:maxIters
% do some work that results in a 1x9 vector
output = ones(1,9);
% save the output to the kth row of the allData matrix
allData(k,:) = output;
end
And that is it. Once outside of the for loop, allData has the output from each iteration.
Try the above and see what happens!

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!