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?

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 comentarios

In MATLAB the term workspace has a specific meaning: "the variables you create and store in memory during a MATLAB session". There are lots of tools for loading data into this workspace. However you do not tell us anything about what form this data is in: is it stored in a file, a database, or some other way? If you are not certain what the correct terminology is, then please explain exactly how these data were made, and then we can help you import the data into the MATLAB workspace, or to make them part of a MATLAB function/script.
Hi, thank you for replying. Basically, the file is a set of data of rainfall from the met office over the last 10 years for each month for a town in the UK. So its for instance: apr04 55.123mm may04 78.99mm
etc.
The file itself when looked at via windows comes up as a "Microsoft Access Table Shortcut". But I load it into my code and it appears in the workspace section. I was wondering how do I get this list to appear in the main body of code. Here is an image of what I mean. Sorry, I am new to Matlab, I am from a c++ background and this is all new to me.
So its not a complied code my Prof is asking for but a "script" and there is the option to upload one file to Blackboard. So it wont be an exe etc, I think he means he wants it all in a matlab code file.
The code was given to me as a Microsoft Access Table. I load it into Matlab under "open" and my code was built from using the data that was given to me. I understand that obviously declaring variables in the editor adds to the workspace. I am just wondering if this is done vice versa to impliment the array into the main body of code. (As all of the monthly rainfall data is not in my main code).
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:
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.

Iniciar sesión para comentar.

Respuestas (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 comentarios

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!
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.

Iniciar sesión para comentar.

Etiquetas

Preguntada:

el 31 de En. de 2016

Comentada:

el 1 de Feb. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by