Saving in 3d matrix Input and Output results from loop

2 views (last 30 days)
Dear all,
I'm quite new to matlab and having problems saving input and output data from a loop. What I'm doing is to run a function changing its three main parameters one at the time, A, B and C, this way:
if true
for A = 1:50;
for B = 1:0.05:200;
for C = 1:300;
[R] = myfunction (A,B,C)
end
end
end
end
The complete code works fine, but I need to save in a 3d matrix the output R AND each value of A, B and C for the corresponding output. Can you help me with an example?
Thanks in advance!
A

Answers (1)

Star Strider
Star Strider on 2 May 2015
A cell array is the best option:
k1 = 0;
for A = 1:50;
for B = 1:0.05:200;
for C = 1:300;
k1 = k1 + 1;
[R] = myfunction (A,B,C)
RABC{k1} = {R, A, B, C};
end
end
end
I arbitrarily called the cell array ‘RABC’. It uses a simple counter to increment it.
  10 Comments
Ac
Ac on 5 May 2015
I tried, but now I am having an error in my tspan of the ode45 solver. I'll try to figure out where is the problem and see if it works.
thanks!

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!