Converting Excel Spreadsheet to Matrix and Storing in Mfile

In summary, the user is looking for a way to convert a matrix in their command window to a specific format, and wants to know if they can store the matrix in a file for future use without relying on the original spreadsheet. The suggested solution involves using the fprintf and save functions.
  • #1
elbarto
33
0
Hi
I have just imported a fairly large matrix from a excel spread sheet (121x6) useing the xlsread function. Is there a way I can convert the matrix from my command window to look something like below.

Matrix = [...; ...; ...; ...; ...; ...]

I want to know if i can store the matrix in a mfile so I can use the data even if i no longer have access to the spreadsheet. I don't really want to use xlsread everytime i need to use the matrix and I want to be able to run the code on different machines if i need.

Thanks in advance

Elbarto
 
Physics news on Phys.org
  • #2
elbarto said:
Is there a way I can convert the matrix from my command window to look something like below.

Matrix = [...; ...; ...; ...; ...; ...]
It can be done in this way (your array is arr)
Code:
[m n] = size(arr);
for i = 1:m
fprintf([num2str(arr(i,:)) ';'])
end
The fprintf prints everything in the same line. num2str converts integer to string. arr(i,:) extracts each row of the matrix. Following are some references:
https://in.mathworks.com/matlabcentral/answers/116593-how-to-display-a-string-and-matrix-in-matlabhttps://in.mathworks.com/matlabcentral/answers/175231-extract-first-row-from-matrixhttps://in.mathworks.com/matlabcentral/answers/16963-how-to-print-in-the-same-line
elbarto said:
want to know if i can store the matrix in a mfile so I can use the data even if i no longer have access to the spreadsheet. I don't really want to use xlsread everytime i need to use the matrix and I want to be able to run the code on different machines if i need.
This can be done using the save function:
https://in.mathworks.com/help/matlab/ref/save.html
 

What is the process of converting an Excel spreadsheet into a matrix in an Mfile?

The process of converting an Excel spreadsheet into a matrix in an Mfile involves several steps. First, the spreadsheet data must be organized into a table format, with rows representing the observations and columns representing the variables. Then, the data must be copied and pasted into an Mfile. Finally, the data must be formatted into a matrix using the appropriate functions and syntax.

What is the benefit of converting an Excel spreadsheet into a matrix in an Mfile?

Converting an Excel spreadsheet into a matrix in an Mfile allows for easier manipulation and analysis of the data. Matrices are a common data format used in scientific computing and can be easily manipulated using various functions and operations. Additionally, storing data in an Mfile allows for easier access and organization of the data.

What is the difference between a spreadsheet and a matrix?

A spreadsheet is a data format commonly used in programs like Microsoft Excel, where data is organized into rows and columns. A matrix, on the other hand, is a data structure used in scientific computing, where data is organized into rows and columns and can be manipulated using various functions and operations. While spreadsheets are useful for data entry and basic analysis, matrices are more versatile and efficient for complex scientific computations.

Can any type of data be converted into a matrix in an Mfile?

Yes, most types of data can be converted into a matrix in an Mfile. However, the data must first be formatted into a table format with rows and columns. Additionally, the data must be numeric or can be converted into numeric form, as matrices can only store numerical data.

How can I store a matrix in an Mfile for future use?

To store a matrix in an Mfile, you can use the "save" function in MATLAB. This function allows you to save the current workspace variables, including your matrix, into an Mfile. You can then load the Mfile in the future to access and use your stored matrix.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
18
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
6K
Replies
34
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • Atomic and Condensed Matter
Replies
0
Views
386
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
993
  • Computing and Technology
2
Replies
41
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
28K
Back
Top