0

My code essentially loads in a .mat file with a number of data arrays in it. As the user names the arrays in this file what they want, the tell my code what the variable names are through a GUI, which saves the array names to a string in another variable.

I need to perform a detrend() on these arrays before plotting them, however the detrend function references the variable name rather than the array.

Example: ... varName = get(handles.edit1,'String') ; %'Data1' ... Load (file.mat) %contains data arrays

Data = detrend(double(varName)); ...

1
  • 1
    I'm not sure to understand the issue. What about using varName = str2double(get(handles.edit1,'String') )? Commented May 12, 2015 at 2:18

1 Answer 1

0

Instead of load('file.mat') which pollutes your code's namespace with the user data, use

userData = load('file.mat');

or even

userData = load('file.mat', varName);

After this, you can do

userData.(varName)

to access the variable whose name is in the string varName, whose contents were read from the file file.mat.

You could even use fieldNames(userData) to find out the array names, instead of requiring the user to remember and type them in.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.