MatLab Subroutine Capabilities for Calculations

I would like to create a program and would like to know if MatLab can be programmed to do what I require.
If so, what is the best way to achieve the desired calculations that interact at different stages with one another.
Example Values:
Data Set 1
1.1 = 18.556732
1.2 = 25.433254
1.3 = 81.151712
1.4 = 96.304015
Data Set 2
2.1 = 18.556854
2.2 = 25.433242
2.3 = 81.152563
2.4 = 96.314000
Data Set 3
3.1 = 18.556844
3.2 = 25.433333
3.3 = 85.000000
3.4 = 96.313025
Desired Calculation:
Step 1 : Have the GUI ask the user the number of values in the first data set
- The user inputs 4
Step 2 : The GUI asks for the alphabetical level of precision required ("A", "B" or "C")
- The user inputs a letter
- That letter references conditions to be met and those conditions are assessed during the input of each data set.
Eg. The user inputs level "A"
Level "A" requires the following
  1. - The running SD (the SD is recalculated during the run time) for each relative input (1.1, 2.1, 3.1, etc)<= 1.5 .
  2. - The Maximum range between respective values of the datasets be <= 2
  3. - The number of data sets required be >= 10.
This is required for every instance of a new data set of values.

5 Comments

Jay
Jay on 9 Mar 2018
Edited: Jay on 9 Mar 2018
Hi Image Analyst,
No this is not homework and the writing of the a program to do what I require (if possible) is not graded.
I am attempting to write a program for my final unit at University that requires reduced field calculations. The intention is to have the program calculate the values to save time during the expedition.
I would prefer to write a rigorous program that minimises the potential of calculation errors (rather than hand calculations).
I can give you the specifics in a private message if you desire as I do not want others to use my code without putting the effort into creating a program themselves.
I have used simplistic values to determine if MatLab can do what I need before I invest the time in attempting to create a program that won't do what I need.
I have used MatLab in my degree and Excel does not allow iteration calculations without the user manually removing values.
I do not want to hardcode values and would like to create a program I can use later on in industry if these type of calculations are required.
"I can give you the specifics in a private message if you desire as I do not want others to use my code without putting the effort into creating a program themselves."
The most active volunteers much prefer to work entirely in public so that everyone can use the knowledge. It is not that we object to commercial organizations or private profits, but we do object to our work being used for exclusive private gain without compensation to us. If you want private consultation, hire a private consultant.
I only object to other students using my code rather than putting the time and effort into the code writing process (not the general methodology).
Specifics are not code. Unless you have gone to the trouble of doing a complete functional breakdown with flow charts and careful interface definitions and data dictionaries and schemas, then your requirements probably do not need to be private.

Sign in to comment.

 Accepted Answer

Prompting for values is not difficult in MATLAB.
Generating random values according to specifications is not necessarily difficult, but a lot depends on the kinds of constraints needed. Some kinds of constraints can be a bit tricky to do fairly, such as generating a list of numbers fairly under the condition that the list sums to a particular fixed value. Fairly choosing random permutations of fixed sets can require some work when the set size gets large enough that the entire class of choices does not fit in memory.

6 Comments

So if I wanted to create a subroutine that would ask for the number of values in the data set and then request the data in that sequence, whilst having each of the relative values calculate the SD and then having a subroutine assess if the derived values require rejection based on the initial subroutine, how would I structure such a program?
My research so far has resulted in that a function can not be called in another function and would require "static methods".
I do not yet comprehend how static methods can be used in what I desire to achieve.
I also read that a script file can not invoke another script file.
If the above is true, I would need to write all the code in a single m file rather than segment the routines into different files to be invoked when required.
Is this comprehension correct?
Jay
Jay on 9 Mar 2018
Edited: Jay on 9 Mar 2018
Can you please elaborate on which task requires what type of structure?
Eg. What structure would be used to have MatLab assess each calculated value to that of a series of prior values using pre-defined criteria which have been segmented into groups for more robust progaming (also catering to easier to follow code writing)?
How can I have subroutines with a series of nested if statements and, have the specified subroutine invoked during each input (specified by the user prior to dataset input)?
Is the only way to complete the desired result to have all the code in a single script file and have the dynamic iterations based on a seperate "add value button" (in the GUI effictively adding an additional iteration) with an iteration count for placement specifier. Said specifier would allocate values in an array for the calculations?
"My research so far has resulted in that a function can not be called in another function and would require "static methods"."
Not true at all. Most MATLAB functionality is implemented as functions that call other functions.
Static methods have only to do with creating object-oriented classes in which you may wish to provide a few class methods that do not require a class object as input. These can be used for utility routines that other people might want to make use of, or they can be used for routines that create objects internally, process on the objects, and return non-object output.
"I also read that a script file can not invoke another script file."
That is not true either.
However, as a matter of programming style and efficiency, you should probably not be using or providing many scripts.
Brilliant.
Do you know where I can find examples of functions executing functions and scripts running scripts as part of an if statement in a master script file?
What published literature would you recommend a University student to read for intermediate MatLab programing?
University student's that are not majoring in software development / IT / programing nor are financially supported by employer's will find it diffucult to financially justify enrolment in the MatLab education unit's.
Unzip this into a convenient directory and cd there in MATLAB. run the function named driver . This will give you a menu of options. script 1 is an example of a script calling a script. script 2 is a script called directly. function 1 is an example of a function calling a function. function 2 is an example of a function being called directly. function 3 is an example of a function calling a script (which is script 1, so it in turn invokes script 2).
Thank you for taking the time to write that up for me Walter.
It is greatly appreciated.
I will mark the post as answered and try to use the examples given to be used as subroutines.

Sign in to comment.

More Answers (0)

Categories

Products

Asked:

Jay
on 9 Mar 2018

Commented:

Jay
on 11 Mar 2018

Community Treasure Hunt

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

Start Hunting!