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

6 Ansichten (letzte 30 Tage)
Summer am 4 Jan. 2015
Kommentiert: Star Strider am 4 Jan. 2015
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.
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Star Strider am 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 Kommentare2 ältere Kommentare anzeigen2 ältere Kommentare ausblenden
Summer am 4 Jan. 2015
Thanks! :)
Star Strider am 4 Jan. 2015
My pleasure!

Melden Sie sich an, um zu kommentieren.

### Weitere Antworten (1)

dpb am 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 Kommentare1 älteren Kommentar anzeigen1 älteren Kommentar ausblenden
dpb am 4 Jan. 2015
Bearbeitet: dpb am 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
>>
Summer am 4 Jan. 2015
Thank you. :)

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Numerical Integration and Differentiation finden Sie in Help Center und File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by