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 次查看(过去 30 天)
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 个评论
Stephen23
Stephen23 2016-1-31
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 2016-1-31
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.

请先登录,再进行评论。

回答(1 个)

Image Analyst
Image Analyst 2016-2-1
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 个评论
Andy Keane
Andy Keane 2016-2-1
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 2016-2-1
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by