Data transfer from excel to matlab!
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Abdullah Türk
il 21 Dic 2018
Commentato: Abdullah Türk
il 21 Dic 2018
Hello to everyone
I want data transfer from excel to matlab. You can see the matrix I want to create in the image.
For example, I want to create [1 1 1] where the matrix intersects the first row and column. How can I do that? Thanks.
0 Commenti
Risposta accettata
Guillaume
il 21 Dic 2018
It would be much easier to help you if attached a demo excel file so we can be sure of the actual format you're using to store the data.
Saying that, it looks like you want to store [1 1 1] in a single excel cell and get that as a matrix of numbers in matlab. That's not a good idea. On the matlab side, to store that you'll either need a cell array (if the vectors are different size) or a 3D matrix (if the vectors are all the same size). Neither can be represented easily in excel so you have to come up with a special storage scheme in excel. The one you have chosen is probably the worst one as it forces you to store the numbers as text which will impose a very slow text to number conversion.
I recommend you come up with a different way to store your data in excel, one where you store the numbers as actual numbers. For example if you want MxN cell array of 1x3 vectors, I'd recommend you store the data as in Mx(Nx3) excel range where each cell contain a single number. You can read that easily with xlsread and split into a cell array with mat2cell:
%data is store as M x (Nx3) 2D array in excel
data = xlsread('somefile.xlsx');
assert(mod(size(data, 2), 3) == 0, 'Width of array in excel is not a multiple of 3')
data = mat2cell(data, size(data, 1), ones(1, size(data, 2) / 3) * 3);
Or you could reshape into a 3d matrix:
%data is store as M x (Nx3) 2D array in excel
data = xlsread('somefile.xlsx');
assert(mod(size(data, 2), 3) == 0, 'Width of array in excel is not a multiple of 3')
data = permute(reshape(data, size(data, 1), 3, []), [1 3 2]); %create a MxNx3 array
Più risposte (1)
madhan ravi
il 21 Dic 2018
Use readtable() to read the excel file
6 Commenti
madhan ravi
il 21 Dic 2018
T=readtable('matrix.xls')
Gives:
Warning: Variable names were modified to make them valid MATLAB identifiers. The
original names are saved in the VariableDescriptions property.
T =
4×5 table
x_111_ x_1_91_71_5_ x_1_51_31_ x_111__1 x_135_
_____________ _______________ _______________ _____________ _________
'[5 7 9]' '[1 1 1]' '[5 7 9]' '[1 1 1]' '[3 5 7]'
'[1 3 5]' '[1/9 1/7 1/5]' '[1 1 1]' '[1/5 1/3 1]' '[3 5 7]'
'[1 1 1]' '[1 1 1]' '[1 3 5]' '[1 1 1]' '[1 1 1]'
'[1/5 1/3 1]' '[1/7 1/5 1/3]' '[1/7 1/5 1/3]' '[1 1 1]' '[1 1 1]'
Vedere anche
Categorie
Scopri di più su Data Import from MATLAB in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!