Using the output of one m-file in Matlab as the input to another? Establishing the connection

1 vue (au cours des 30 derniers jours)
I have created the functions but dont know how to proceed? like how to establish the connection?
Let's say that:
1) the first function produces a concentration profile with respect to time for a given period of let's say 1 hour of exposure: C(t)
2) The second function computes dosage as D(c,t)= C^a * delta t, where C is found in 1 and a is a constant
Dosage is computed for 4 different time intervals so that the final outcome is D1 (for the first time interval, say the first 10 minutes), D2(for the second time interval, and is accumulative such that D2 = D1+ C2*deltat2),...etc
Also, how can I write the code for the dosage such that it's computed not only once but 4 times, each time for a given time interval
Hope my question is clear, and sorry for the so many questions. I haven't used Matlab since 2008-2009.
Thanks in advance.

Réponse acceptée

Star Strider
Star Strider le 4 Jan 2015
A for loop would be appropriate.
Save the concentration profile that you output from the first function as either a vector of concentrations, or if it computes its own times, a matrix of times and concentrations. Index it using the index variable (loop counter) of your loop.
Then use whatever information you need from the vector or matrix computed by the first function as an input argument to the second function. Save those outputs as well, indexed by the index variable (loop counter) of your loop. If the length of the output changes between iterations, use a cell array to store the results.
The previous data you computed will be available in the next iteration if you need them, since you have saved them and they are still in your workspace.
When the loop finishes, I would save all the results in a .mat file so I can use them later, without having to recompute everything.
  4 commentaires

Connectez-vous pour commenter.

Plus de réponses (1)

dpb
dpb le 4 Jan 2015
Given the function (let's call it f1) and the vector t over which to compute...
C=f1(t); % the concentration
D=trapz(t,C); % the dose integral
  3 commentaires
dpb
dpb le 4 Jan 2015
Modifié(e) : dpb le 4 Jan 2015
doc cumsum
From the example for trapz
>> y=reshape(0:5,2,3);
>> dt=0.1;
>> t=0:dt:0.2;
>> trapz(t,y,2)
ans =
0.4000
0.6000
>> cumsum(y,2)/(3/2)*dt
ans =
0 0.1333 0.4000
0.0667 0.2667 0.6000
>>

Connectez-vous pour commenter.

Catégories

En savoir plus sur Numerical Integration and Differentiation 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!

Translated by