How can I calculate the average deviation for two values that are in two separate variables files?

I want to calculate the average deviation flow rate per day. The data value is in one variable and the value in the model is in another variable

 Risposta accettata

Hi Francisca,
As per my understanding you want to access a variable in one file that is defined in another. To do this, you can output your variable in one file. Then, access it from the second file by calling a function. To elaborate:
In file 1, where the variable is defined, use the following code:
function myVar = data()
myVar = 100;
end
In file 2, where you want to use the variable, use the following code:
function myFunc()
myVarFromFile1 = data(); % myVarFromFile1 takes the value defined in file 1
end
Hope this helps! Thanks!

4 Commenti

Hi,
Thanks for the help but I'm not sure if I fully understand.
I want to access two different colums in two different variables and calculate the deviation per row (the row is the same in the two, is the time).
How can I do that?
Hey, thanks for clarifying that.
I understand that you want to calculate the average deviation per row for two columns which are in two different variables.
You can access the columns in question using array indexing. The code is as follows:
col1 = myVar1(:, i) % gives the ith column of myVar1
col2 = myVar2(:, j) % gives the jth column of myVar2
Then you can compute deviation using the 'mad' function. Code is as follows;
myMat = [col1; col2]; % concatenate the 2 columns
mad(myMat); % compute mean absolute deviation
This will return a row vector containing the mean absolute deviation of each column of 'myMat'.
For more information regarding the 'mad' function, please refer the following documentation: https://www.mathworks.com/help/stats/mad.html
Hope this answers your question. If not, sending data relevant to the question will help me answer better. Thanks!
Thanks for the information and all the help.
It worked!
That's great to hear. If the answer was helpful, please do consider accepting it. Thanks!

Accedi per commentare.

Più risposte (0)

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by