outputname of variable depending on inputname

6 views (last 30 days)
Hello everybody,
I wrote a function which smoothes data and I did it as general as possible, in order to that I renamed the input data to X:
function [] = Curvesmoothing(filename, curvename, range)
%% load data
X = load(filename, curvename);
X = X.(curvename);
...calculations
Xsmooth = [smoothedX]
But now I don't want to save the result with this meaningless name, but rather with its inputname and the information how many circumjacent values were used for the smoothing, i.e. curvename + "smooth" + range. And this into the origin file, because I want to be able to feed the function with data, undependent of its origin. Now is my Question how I get Matlab to rename Xsmooth into a specific name, depending on other variables.
e.g. I tried to do it by creating a structure, similiar to my approach above, but I ended up with a structure named S, which contains the array (with the right name & data), but I could not figure out how to extract this array (see below).
Q = curvename + "smooth" + range;
S.(Q) = Xsmooth;
save(filename, curvename + "smooth" + range , '-append')
I also already figured out how to specify the filename, but I don't want to create too many .mat files, in order to keep some tidiness in my data.
Best Regards
Fabian

Answers (1)

Fangjun Jiang
Fangjun Jiang on 25 Mar 2020
utilize inputname()
  2 Comments
Fabian Jakobs
Fabian Jakobs on 25 Mar 2020
could you may clarify that? I cannot see how to use the function in my context

Sign in to comment.

Categories

Find more on Preprocessing Data in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!