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?
Mostrar comentarios más antiguos
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
Stephen23
el 31 de En. de 2016
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.
Andy Keane
el 31 de En. de 2016
Andy Keane
el 31 de En. de 2016
Andy Keane
el 31 de En. de 2016
Stephen23
el 31 de En. de 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):
http://www.mathworks.com/matlabcentral/fileexchange/19953-uneval-var-name--value--return-cell-array-
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
el 31 de En. de 2016
Respuestas (1)
Image Analyst
el 1 de Feb. de 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 comentarios
Andy Keane
el 1 de Feb. de 2016
Image Analyst
el 1 de Feb. de 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.
Categorías
Más información sobre Spreadsheets en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
