How to extract data from a function or functions. Also how to export this data to excel.
9 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Konard Adams
il 14 Ott 2021
Commentato: Konard Adams
il 18 Ott 2021
I have written two sets of codes. I placed them in two separate folders as program 1 and program 2.
Now with the code calling the inverse and looping. How do I extract the data? There is nothing in workspace.
Program 1 demonstrates the actual movement of the linear motion and program 2 is just the stationary output.
Is there a way to extract these data to excel?
Both programs are attached.
0 Commenti
Risposta accettata
Bjorn Gustavsson
il 14 Ott 2021
Your functions have their own name-space where the variables that are defined exists (in addition to the input variables that you feed the functions with). When the functions complete these variables cease to exist, they are no more. To get the results of interest out you have to define (and assign) some output-variables in your function-files. This typically looks something like this:
function [r_out,flag] = position_along_line(l,r0,e_line)
Here a variables r_out and _flag are defined as output from the function and have to be defined in the function. This way your function calculates something and returns the result. You'll have to adjust your "programmes" similarly. One way to get all the results from a programme is to not have it defined as a function but use it as a script - then all of the calculations will be done in the base workspace and exist after the script has finished - the main drawback is that it is easy to develop scripts that rely on other variables to exist without noticing which gives the scrip some hidden dependencies.
Also avoid the "clc, clear all" trope inside functions it is usless, in scripts it is anoying.
HTH
7 Commenti
Bjorn Gustavsson
il 18 Ott 2021
My pleasure.
(I saw your most recent question, but thought: You'll become a much better programmer by figuring that out yourself - it's not nice sort-term but on any longer time-scale than 3 days it is to be preferred. Now you can swim!)
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
