Converting Excel Spreadsheet to Matrix and Storing in Mfile

  • Context: MATLAB 
  • Thread starter Thread starter elbarto
  • Start date Start date
  • Tags Tags
    Excel Matrix
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 reply · 4K views
elbarto
Messages
32
Reaction score
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
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