How to extract data from a function or functions. Also how to export this data to excel.

조회 수: 46 (최근 30일)
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.

채택된 답변

Bjorn Gustavsson
Bjorn Gustavsson 2021년 10월 14일
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
Bjorn Gustavsson
Bjorn Gustavsson 2021년 10월 18일
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!)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by