I need to hand in one script as my final project, how do I do this when I have a separate workspace that was made in excel?

1 view (last 30 days)
Hi guys, I have to hand in my complete Matlab script but the problem is that the workspace was made by a project partner in excel (I think). So I have to load the array separately after loading my matlab code. How do I "Import" all of those variables from the array in the workspace into the code to make it one script file? We have to hand in one matlab script, not "a script and a workspace", if you know what I mean? Many thanks in advance.
  6 Comments
Stephen23
Stephen23 on 31 Jan 2016
Of course normally it is considered good practice to keep code and data quite separate, so there are no easy ways to convert data (external, or in the workspace) into some text that can be put in a script. However, if you really can only submit one file then there is not much choice...
You might like to take a look at these FEX submssions, which claim to be able to turn variables into strings (that could be inclued in your script):
I do not use Microsoft products, so I cannot help you with accessing the database. I can only add that you should not use individually numbered variables (as are indicated in your screenshot), here is why:
Andy Keane
Andy Keane on 31 Jan 2016
Such is the bummer of project work. You have to deal with other people! I'll give that a look over, you would think there would be an easy way to just import the data in. In fact, I think he might have used matlab to create it. it has the A variable for the array in it.

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 1 Feb 2016
You have a .mat file. Most likely it's a MATLAB file, not a Microsoft Access Table file. See this support document: http://www.mathworks.com/matlabcentral/answers/103000-why-have-all-my-mat-files-become-associated-with-microsoft-access
Your script can read in the xlsx or mat file with a function call like xlsread(), readtable(), or load(). If you can't have a separate file, then you can read it in and type the name of the variable in the command window. Then copy all the stuff it spews out and paste it into a script editor window. Add brackets to make it an assignment. For example to get "x",
>> x
x =
0.939001561999887 0.550156342898422 0.587044704531417 0.301246330279491
0.875942811492984 0.622475086001227 0.207742292733028 0.470923348517591
Then just add opening and closing brackets to make it into an array:
x =[...
0.939001561999887 0.550156342898422 0.587044704531417 0.301246330279491
0.875942811492984 0.622475086001227 0.207742292733028 0.470923348517591];
% Note how I added ]; at the end to finish the array.
Now that can be in the script with all the rest of your commands.
  2 Comments
Andy Keane
Andy Keane on 1 Feb 2016
This looks perfect! Thanks! I will give this a go in uni and let you know how I get on, I figured it may involve the "load" function. Cheers!
Image Analyst
Image Analyst on 1 Feb 2016
OK, let me know how it goes. The command window may not be able to hold all the printout if your array is huge. I'm not sure how much it can hold before you lose them off the top of the command window.

Sign in to comment.

Categories

Find more on Environment and Settings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!