Transform column data to m x n matrix
Afficher commentaires plus anciens
Hi, I have 3 column data and want to transform it into an m x n matrix. Please see the attached file for an example.
Réponse acceptée
Plus de réponses (3)
Kevin Chng
le 17 Oct 2018
Modifié(e) : Kevin Chng
le 17 Oct 2018
Hi
The best solution is :
Drag your excel and drop it in MATLAB command window.
It will pop out a app for you to configure your excel input.
Since there are char in 2nd column, therefore I stored them in table data type instead of matrix.
opts = spreadsheetImportOptions("NumVariables", 3);
opts.Sheet = "Sheet1";
opts.DataRange = "A4:C29";
opts.VariableNames = ["Key1", "Key2", "values"];
opts.VariableTypes = ["double", "categorical", "double"];
opts = setvaropts(opts, 2, "EmptyFieldRule", "auto");
DataTransformation = readtable("DataTransformation.xlsx", opts, "UseExcel", false);
clear opts
Code above is generated through the application.
However, I saw there are other data or table in your excel sheet, if you want to import them in other table, just repeat the method what i say : Drag the excel sheet and drop it in MATLAB command window, select the range and data type you wanted to export them.
2 commentaires
Maneesh
le 18 Oct 2018
Kevin Chng
le 18 Oct 2018
Read table from Original Data, then write it to Transformed Data according to its pattern?
Image Analyst
le 17 Oct 2018
Have you tried reshape()?
arraymxn = reshape(originalMatrix, m, n);
1 commentaire
Maneesh
le 18 Oct 2018
madhan ravi
le 18 Oct 2018
Modifié(e) : madhan ravi
le 18 Oct 2018
[num,txt,raw]=xlsread('DataTransformation.xlsx')
[m,n]=size(num)
num(isnan(num))=[]
data=reshape(num,m,n) %m and n can be your choice but make sure m times n == number(num)
3 commentaires
Kevin Chng
le 18 Oct 2018
Hi madhan,
you open his file, you will notice that two tables are totally different format, some logic have to apply for matching them. Title is bit misleading.
madhan ravi
le 18 Oct 2018
yes I don't understand what the OP wants
Maneesh
le 18 Oct 2018
Catégories
En savoir plus sur Spreadsheets dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!