Is it possible to assign variables to a script?
Show older comments
I am running a script that uses the same notation for the equations, but one script is for the month of January and the other is for the month of May. Is there a way to keep the variables seperate if i was to run the scripts together to compare one against the other?
7 Comments
Walter Roberson
on 2 Aug 2019
... Make it into a function that you pass the data (or name of data file) into.
rammah nagi
on 2 Aug 2019
dpb
on 2 Aug 2019
doc function
rammah nagi
on 3 Aug 2019
Edited: rammah nagi
on 3 Aug 2019
dpb
on 3 Aug 2019
"doc function" was hint to read the documentation for the function keyword to learn the essence of writing functions...
You either write a function that calls the calculation with the necessary input to identify the case being operated on and return the result in different variables or as cell array or in this case it could be a 2D array since both are same length...that's your choice in how you wish to write it.
Or, you plot the first case, then use
hold on
and add the second...
Since we "know nuthink!" about what this function is, it's not possible to say much about actual specific code.
rammah nagi
on 3 Aug 2019
Walter Roberson
on 3 Aug 2019
Edited: Walter Roberson
on 4 Aug 2019
function [hour, Pout] = MyFunction(month)
... Appropriate code that assigns to hour and Pout
Then
[h1, p1] = MyFunction('Jan');
[h2, p2] = MyFunction('May');
plot(h1, p1, h2, p2)
Accepted Answer
More Answers (0)
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!