Load .mat file variables without overwriting current variables of the same name

13 views (last 30 days)
I have variables x and y in my workspace. Now I'd like to load a .mat file that contains variables named x and y. For example,
x = 5;
y = 6;
load wind
How can I get variables x and y from wind.mat without overwriting my other variables named x and y. I want to do this without renaming my original x and y, and create wind_x and wind_y when loading wind.mat.

Accepted Answer

Matt J
Matt J on 6 Aug 2014
Edited: Matt J on 6 Aug 2014
You should always call LOAD with an output argument, regardless of whether you are worried about overwriting variables,
S=load('wind');
x2=S.x;
y2=S.y;
  1 Comment
Chad Greene
Chad Greene on 6 Aug 2014
Brilliant. You've saved me some real headaches and finally answered a question I've had for some time. Thanks Matt.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!